Win a copy of Design for the Mind this week in the Design 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