File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Variable hiding" Watch "Variable hiding" New topic

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
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 might help.

I agree. Here's the link:
subject: Variable hiding
It's not a secret anymore!