posted 19 years ago
For your second piece of code, a call to super() is inserted by the compiler into Mobile's constructor, which invokes Phone()'s constructor, hence the first line of output. Phone's constructor then invokes the overridden showDevice method in Mobile, since Mobile is the declared type vs a reference type of Phone.
However, String device in the mobile object is null until after its super classes constructor has finished running, so you get the following line of output: Mobile.showDevice,null.
Phone's constructor then completes and the rest of the program is executed straightforwardly. At least that's my take on it.
If you're having trouble following the execution of code like this, I find it useful to step through it using a debug tool, like in Eclipse or something similar.
Hope this helps
nimai
[ April 12, 2005: Message edited by: Nimai Etheridge ]