现在有两个类:Father(父类)和Child(子类),Child类继承了Father类。
代码如下:
Father
public class Father {
int numFather = 10;
public Father() {
System.out.println("我是父类。");
}
}
Child
public class Child extends Father{
int numChild = 20;
public Child() {
System.out.println("我是子类");
}
}
测试类
public class Test {
public static void main(String[] args) {
Child child = new Child();
}
}
接下来在添加断点debug运行
观察父类和子类的属性初始化顺序,以及父类和子类中构造方法内容执行顺序(变量是成员变量,成员变量有默认值,int类型默认值为0。)