是不是在调用子类构造函数时会自动调用父类的构造函数 class father {
public father() {
System.out.println("I'm father ");
}
}
public class son extends father{
public son () {
System.out.println("I'm son");
}
public static void main(String args[]) {
father f = new father();
son s = new son ();
}
}
输出
I'm father
I'm father
I'm sun
public father() {
System.out.println("I'm father ");
}
}
public class son extends father{
public son () {
System.out.println("I'm son");
}
public static void main(String args[]) {
father f = new father();
son s = new son ();
}
}
输出
I'm father
I'm father
I'm sun
public son () {
System.out.println("I'm son");
}等价于 public son () {
super();
System.out.println("I'm son");
}