this的一些作用,super关键字
2017-10-09 15:18
211 查看
this:
1.等价构造方法的对象class A{
int a;
public void setA(int a){
this.a=a;
}
}
这里的this代替了A的对象,通过对象.数据域来获取引用;
2.等价构造方法
public class Test extends A{
sysout.println("111111");
}
class A{
public A(){
this("a");
sysout.pringln("bbbbbbb);
}
public A(String t){
sysout.pringln("ccccccc");
}
}
输出结果是:ccccccc
bbbbbbb
1111111
这里的this等价于调用了类内部的含参数的方法A(String t){};
Super:
有两种用法:①.调用父类的构造方法
②.调用父类的方法
①.
上面的setColor和setFilled是父类中的方法,可以用下面的super(color,filled)代替,因为父类中有一个这样含参的构造方法
在java中super表示调用父类(基类)的函数: 如果super()表示调用父类的构造函数, super.method表示调用父类中的函数(非构造函数)
相关文章推荐
- java中关键字 this 和super的作用及用法
- java this和super关键字 有什么作用
- 面试题:this和super关键字分别代表什么?以及他们各自使用场景和作用?
- Java基础进阶_day02_(类的组合,继承,this与super关键字)
- Super this 关键字
- Java关键字介绍之this与super
- Java关键字this、super使用总结
- 【python】class之super关键字的作用
- Python中super关键字的作用
- this super static final关键字
- java方法的重载,重写,super,this,final关键字
- Java关键字this、super使用总结
- Python中super关键字的作用
- Java关键字this、super使用总结
- java中super关键字的作用
- Java复习(一)-关键字this,super的用法
- Java中this,super关键字
- this关键字的作用
- Java 关键字 this super 使用总结
- java中的this和super关键字