This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inheritance Doubt

 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why there is no conflict between declaration of variable i in class Two with the one declared in class three?

I know there is nothing like variable overriding. If I declare i in subclass then it supercede the one declared in superclass.
[ December 30, 2008: Message edited by: Vishal Pandya ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is another one of those questions where the answer is "because that's how they designed it." The important thing to realize is that the variable in class three hides or shadows the one in class Two. They're two separate variables, and an instance of class three contains two different int variables named "i". For example,

 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks EFH
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic