public class Son extends Base {
private int i = 22; //12
{
System.out.println("private int i = "+i); //13
}
public Son() { //3
i = 222; //14
System.out.println("i: " + i); //15
}
public void display() { //9
System.out.println("2 Base: " + i); //10
System.out.println("i==="+i); //11
}
}
public class Base {
private int i = 2; //5
{
System.out.println("private int i = "+i); //6
}
public Base() { //4
System.out.println("I base: " + i); //7
this.display(); //8
}
public void display() {
System.out.println("i==="+i);
}
}
public class Test {
public static void main(String[] args) { //1
new Son(); //2
}
}
private int i = 2
I base: 2
2 Base: 0
i===0
private int i = 22
i: 222
When and where was the 'i' defined before printing in "System.out.println("2 Base: " + i);"?
It is a default value.
--- Update ---
Ha,ha.I got it.They have been defined when we creat an instance.But they haven't been initialized.That's why the value of 'i' is 0.Right?