wood burning stoves 2.0*
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP 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
 
Don't get me started about those stupid light bulbs.
 
subject: problem #13, p.168 of Sierra and Bates book