为什么在派生类构造函数中调用超类构造函数时 id = 0 的值?创建子对象时,何时在堆中为该对象分配内存?在基类构造函数运行之后还是之前?
class Parent{
int id = 10;
Parent(){
meth();
}
void meth(){
System.out.println("Parent :"+ id);
}
}
class Child extends Parent{
int id = 5;
Child(){
meth();
}
void meth(){
System.out.println("Child :"+ id);
}
}
public class OverRidingEg {
public static void main(String[] args) {
// TODO Auto-generated method stub
Child a= new Child();
}
}