Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inheritance

 
Arsen Lupen
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47253
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47253
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47253
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you have understood what it happening Well done.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic