Amit Kumar Das ________________________________________
Joined: Jul 19, 2004
Using code tags for ur code
Ok what happens here is: 1) before the mobile constructor runs, the super class constructor is called and when it happens the instance variable are still in the uninitialized state. 2) U can see that during super class constructor call u have showDevice() method called. Now this showDevice() method will be called for the Mobile object. This is becuase as u know method is called based on the object, so here the object is Mobile, so its method is called. 3) Now since ur variable "device" is still not initialized, its considered to be null. Thats why ur output consists of null
After the super class constructor completes its running, the subclass constructor is run and thus the variable gets initialized.