wood burning stoves*
The moose likes Beginning Java and the fly likes Inheritance Doubt 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 » Java » Beginning Java
Bookmark "Inheritance Doubt" Watch "Inheritance Doubt" New topic

Inheritance Doubt

Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374

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

Joined: Jul 08, 2003
Posts: 24183

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,

[Jess in Action][AskingGoodQuestions]
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
Thanks EFH
It is sorta covered in the JavaRanch Style Guide.
subject: Inheritance Doubt
Similar Threads
Variable shadowing
Variable scoping
compile time constant and final variable
Protected and default access of a class member
diff types of Variables & methods