wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Variable hiding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Variable hiding" Watch "Variable hiding" New topic
Author

Variable hiding

lu v thuan
Ranch Hand

Joined: Oct 25, 2001
Posts: 32
Hi Friends

I think the result is :15 , 15
Am i wrong, if so pls make it clear to me?
Thank in advanced
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
The answer is 15 and 5.
The cast you have made here ((A)bobj))is equivalent to assigning a base class reference to a superclass type. Hence the i in the superclass gets invoked. Do take a look at this modified code and run it...it might help.

HTH
Shyam
 
jQuery in Action, 2nd edition
 
subject: Variable hiding
 
Similar Threads
How to write generic method for this method?
Protected in subclasses
constructor invocation order/priority
Why the output is 2 here?
can parent class constructor be invoked using this operator?