This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft 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 Java 8 in Action this week in the Java 8 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: 36599
    
  16
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: 36599
    
  16
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: 36599
    
  16
I think you have understood what it happening Well done.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inheritance
 
Similar Threads
Mock exam question
a simple quetion,help
Overloading and Overriding
How does inheritance work
Array Help