Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
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 Badass: Making Users Awesome this week in the Game Development forum!
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