This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Rachel Glenn
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 333
Firefox Browser Java Windows XP
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic