class test1{
int y=20;
public test1(){System.out.println("father_no_arg");
}
public test1(int i){this();System.out.println("father_int_arg"+y);}
}
public class test extends test1 {
int x=9;
public test(){System.out.println("no_arg");
}
public test(int i){this();System.out.println("int_arg"+x);} public static void main(String[] args) {
test l=new test(12);
}
}
大家看看结果是什么另我学c++的时候好像看到过如果子类继承父类的函数如果行为一样知识具体值不一样不会重载,构造函数会这样么?
int y=20;
public test1(){System.out.println("father_no_arg");
}
public test1(int i){this();System.out.println("father_int_arg"+y);}
}
public class test extends test1 {
int x=9;
public test(){System.out.println("no_arg");
}
public test(int i){this();System.out.println("int_arg"+x);} public static void main(String[] args) {
test l=new test(12);
}
}
大家看看结果是什么另我学c++的时候好像看到过如果子类继承父类的函数如果行为一样知识具体值不一样不会重载,构造函数会这样么?
输出father_no_arg又由于
public test(int i){this();System.out.println("int_arg"+x);}中有 this()所以第二次应该输出 :no_arg
最后输出:'int_arg" + x 即: 'int_arg9