This week's book giveaway is in the OCAJP forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
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 OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP 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