This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes problem #13, p.168 of Sierra and Bates book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "problem #13, p.168 of Sierra and Bates book" Watch "problem #13, p.168 of Sierra and Bates book" New topic
Author

problem #13, p.168 of Sierra and Bates book

Rachel Glenn
Ranch Hand

Joined: Oct 24, 2012
Posts: 95
The base class Mammal has a String variable called name.
The subclass, Zebra, also has a variable called name.

Why does this compile? What am I missing? Doesn't Zebra inherit the superclass member variables?

Enkita mody
Ranch Hand

Joined: Aug 06, 2012
Posts: 333

R Gle wrote:The base class Mammal has a String variable called name.
The subclass, Zebra, also has a variable called name.

Why does this compile? What am I missing? Doesn't Zebra inherit the superclass member variables?



It is called hiding.if you want to use superclass's name in subclass then write super.name in subclass.


OCA7
 
jQuery in Action, 2nd edition
 
subject: problem #13, p.168 of Sierra and Bates book
 
Similar Threads
instance variable inheritance
Upcasting doesn't work as intended; clarification needed
ZooKeeper
Question in scjp study guide (Kathey & Bates) page 181- oo Concepts
I need to help with the question 13 chapter 2