我想了解下面java玩具程序的输出......
public class BaseWithPrint {
public BaseWithPrint(){
print();
}
public void print(){
System.out.println("BaseWithPrint.print");
}
}
class DerivedWithPrint extends BaseWithPrint{
int i = 47;
public void print(){
System.out.println("i = " + i);
}
}
class Initialization_MYCLASS{
public static void main(String args[]){
DerivedWithPrint dp = new DerivedWithPrint();
dp.print();
}
}
此文件的输出为:
i = 0
i = 47
我理解为什么我得到了第二行。但是第一行i = 0
?