Try to enjoy your work while doing it,it will Automatically convert in Hard Work...
praveen kumaar wrote:
Anyway,what do you think is the reason behind the first line in the output-i mean why it is not Base?
Praveen
No,it's correct.have a look at one more thing:try to think about output of this statement after line 15 in main()→((Base) b).amethod();Gautham wrote:Hi Praveen.
I thought, it was because of method overriding. Is that wrong?
Try to enjoy your work while doing it,it will Automatically convert in Hard Work...
Gautham Muralidharan wrote:
It worked.
Gautham Muralidharan wrote:In what order does the initialization takes place?
At what point the subclass gets initialized?
Henry Wong wrote:
Second, the initialization order (for the constructor) for the class is, the super(...) is called, the instance variables (and instance initializers) are called (in source code order), and finally, the rest of the constructor is called. So, when the superclass constructor is running, the instance variables still have their default values -- which in the case of int, is zero.
Gautham Muralidharan wrote:((Base) b).amethod();
should give the output
Derived.amethod()-1
It worked.
Try to enjoy your work while doing it,it will Automatically convert in Hard Work...
Gautham wrote:In what order does the initialization takes place?
At what point the subclass gets initialized?
Try to enjoy your work while doing it,it will Automatically convert in Hard Work...
Don't get me started about those stupid light bulbs. |