abstract class abs { abstract void draw(); abs() { System.out.println("before draw"); draw(); System.out.println("after draw"); } } class sub extends abs { int r=1; sub(int r) { this.r=r; System.out.println("sub class constructor:"+r); } void draw() {System.out.println("draw in sub:"+r);} public static void main(String a[]) { new sub(7);} } The o/P: before draw draw in sub: 0 after draw subclass constructor. In the above o/p, I am not able to understand ,why the value of r is printed as 0 even when initialised to 1. ThankYou.
Thats pretty tricky - I think it has to do with the order in which things are done in constructors. I think it is: 1. Memory is reserved and initialized to zero 2. parent constructors all the way back to Object are called 3. the remainder of the sub() constructor is executed. In step 2, the value it finds is initialized memory. Bill