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 Inheritance 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" Watch "Inheritance" New topic
Author

Inheritance

Arsen Lupen
Greenhorn

Joined: Nov 20, 2008
Posts: 15
Hi all,
Could you please tell me the difference?why i am getting different results.
And also try to remove method korcan from Class B.again the different result.I think if we can define the difference everybody will understand Casting.


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38087
    
  22
Welcome to JavaRanch

Please tell us all the details; what different results are you receiving?

Look at our FAQ; you realise that the bit about overriding and hiding applies to fields as well as to static members of the class? That is as much as I shall say at the present. See if you can work out what is happening from the types of the reference (A a = . . . or B b = . . .) and knowing that the field in the subclass hides the field in the superclass.
Arsen Lupen
Greenhorn

Joined: Nov 20, 2008
Posts: 15
Thanks for your response,
the difference is when i try to print the variable koco vie korcan method
i see that it prints 10.but when i tried to print a.koco and b.koco it prints not 10 but 5.trying to understand creating new object with new B() will override the variable?if yes what is the difference between printing via objects own methods and directly via object variables
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38087
    
  22
Variables aren't overridden. Did you read the FAQ I quoted? The same applies to fields; they hide each other rather than overriding.
Arsen Lupen
Greenhorn

Joined: Nov 20, 2008
Posts: 15
Ok.
Thanks a lot buddy.
i did not suppose that variables also behaves like static method shadowing.
in fact it is not good to reach to class variable without getter methods but if we have we should do it by super.koco..
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38087
    
  22
I think you have understood what it happening Well done.
 
 
subject: Inheritance
 
Similar Threads
How does inheritance work
Array Help
Overloading and Overriding
Mock exam question
a simple quetion,help