Just to give a complete answer, in case someone overlooks some details. When you create a new WhatsGoingOnHere instance in the main method, the constructor of that class is called, and in its turn it first invokes the superclass constructor: this invocation was inserted by the compiler.
The superclass constructor ThisisOK( ) on it's turn invokes the method call(). The method call() is overridden in the subclass and it will be the method that will be performed at runtime since it's invoked with an instance of the subclass.
So, call() will print b=... But, what happens is that, when the superclass constructor is called, the member variable int b is not initialized to 16 yet. Therefore the program prints 0 where you expected 16.
[ July 03, 2004: Message edited by: Gian Franco Casula ]
[Edited typo 6 -> 16] [ July 03, 2004: Message edited by: Barry Gaunt ]
"Eppur si muove!"
posted 14 years ago
Thanks for the help....
Ever since I found this suit I've felt strange new needs. And a tiny ad: