**
this()调用构造器作用
**
构造器中this()表示调用形式参数相同的同一个类中的另一个构造器,这样就可以代码复用
class Father {
int age;
/*public Father() {
System.out.println("Father的无参构造方法");
}*/
public Father(String name) {
System.out.println("Father的带参构造方法");
}
}
class Son extends Father {
public Son() {
super("111");
System.out.println("Son的无参构造方法");
//
super("111");
}
public Son(String name) {
//
super("222");
// this 调用无参构造器
this();
System.out.println("Son的带参构造方法");
}
}
public class ExtendsDemo {
public static void main(String[] args) {
//创建对象
Son s = new Son();
System.out.println("------------");
Son s2 = new Son("宝宝"); }
}