this
对象本身。public class ThisTest {
ThisTest tTest;
public ThisTest(){
tTest = this;
}
public void test(){
System.out.println(this);
}
public static void main(String arg[]){
new ThisTest().test();
}
}
成员方法引用。
成员变量引用。public class ThisTest {
String name;
String password;
public ThisTest(String name,String password){
this.name = name;
this.password = password;
}
public static void main(String arg[]){
ThisTest tTest= new ThisTest("fanqd","123456");
System.out.println(tTest.name);
System.out.println(tTest.password);
}
}
在构造函数内部第一行,调用本类另一个构造函数。public class ThisTest {
String name;
String password;
public ThisTest(int age){
this("liulingling", "666666");
}
public ThisTest(String name,String password){
this.name = name;
this.password = password;
}
public static void main(String arg[]){
ThisTest tTest= new ThisTest(20);
System.out.println(tTest.name);
System.out.println(tTest.password);
}
}
Super
父类方法引用。
父类成员变量引用。
在构造函数第一行,调用父类构造函数。public class SuperTest extends Father {
public SuperTest(String name,int age){
super(name, age);
}
public SuperTest(){
super(); //可以省略,子类会自动调用父类的默认构造函数
}
public static void main(String arg[]){
SuperTest st = new SuperTest("fanqd",30);
System.out.println(st.name);
System.out.println(st.age);
SuperTest df = new SuperTest();
}
}