package Test;
public class A {
public A() {
System.out.println("Enter construct A...");
init();
}
public void init() {
System.out.println("Enter A's init...");
}
}
package Test;
public class B extends A {
int i = 0;
int j;
public void init() {
System.out.println("Enter B's init...");
i = 100;
j = 100;
}
public void printAll(){
System.out.println(i);
System.out.println(j);
}
/**
* @param args
*/
public static void main(String[] args) {
B b = new B();
b.printAll();
}
}
package Test; public class A { public A() { System.out.println(Enter construct A…); init(); }
Share
Okay, new B gets first an A get created, first instance fields, then calling B’s init() which sets i and j to 100. Then the B gets created, which initializes the i to 0.