是否会初始化实例变量?但是no-arg构造函数是否初始化实例字段?
示例代码: -
class GenericAnimal{
private String name;
GenericAnimal(){
System.out.println("parent constuctor");
}
}
public class PolymorphismTest extends GenericAnimal {
PolymorphismTest(){
System.out.println("child constructor");
}
public static void main(String[] args) {
new PolymorphismTest(); //creating an object of child class
}
}
输出: -
父母建筑师
子构造函数