File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 24199

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
I agree. Here's the link:
subject: Inheritance Doubt
It's not a secret anymore!