java this super
this |
|
|||
super |
|
class superClass {
public static String string = "在superClass中的静态字符串!";
public superClass() {
this(string);
System.out.println("superClass中的无参数构造函数!");
}
public superClass(String string) {
System.out.println("在superClass打印string的值:"+string);
}
}
class ThisClass1 extends superClass{
public static String string = "在ThisClass1中的静态字符串!";
public ThisClass1() {
this(string);
System.out.println("ThisClass1中的无参数构造函数!");
}
public ThisClass1(String string) {
System.out.println("在ThisClass1中打印string的值:"+string);
}
}
class ThisClass2 extends superClass{
public static String string = "在ThisClass2中的静态字符串!";
public ThisClass2() {
super(string);
System.out.println("ThisClass2中的无参数构造函数!");
System.out.println("打印super.string:" + super.string);
System.out.println("打印this.string:" + this.string);
}
public ThisClass2(String string) {
System.out.println("在ThisClass2中打印string的值:"+string); //未执行
}
}
public class main {
public static void main(String[] args) {
System.out.println("============ new ThisClass1 ============");
ThisClass1 thisClass1 = new ThisClass1();
System.out.println("============ new ThisClass2 ============");
ThisClass2 thisClass2 = new ThisClass2();
System.out.println("============ end! ============");
}
}