This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes OOP - Inheritance Question 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 "OOP - Inheritance Question" Watch "OOP - Inheritance Question" New topic
Author

OOP - Inheritance Question

Madan, Gopal
Ranch Hand

Joined: Aug 13, 2001
Posts: 86
Hi:
I have an ancestor class Top with a private int "i" (say 5) and a public getValue() function that returns the integer value "i";
I created a descendant class Next from the above class and re-declared and initialized a private integer variable "i" (say to 10). But no new getValue() function here, as it is inherited from the ancestor.
My question is how can i get to print the value of integer i in the Next class (10), without Overriding the getValue() method from class Top.
Is it possible to get 10 to print, other than directly accessing the variable or using a getValue() method at class Next?
Thanks
Madan
//Top.java

[This message has been edited by Cindy Glass (edited October 05, 2001).]
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

In a word, no.
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: OOP - Inheritance Question
 
Similar Threads
Why ClassCastException at run time
Private modifier problem
how to swap two integers inside a function ?
Mock question on polymorphism
how to decide valid polymorphic call