Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

public Class variables and inheritance

 
Tejas Aryan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a very basic behavior and I am posting just to make that I understand this properly:



The reason the output : 9 is that class members are not overridden like methods and the value of variable is determined by the type of reference variable.. Please correct, if I am wrong or missing something. If someone can explain more clearly the please post..

Thanks,
Gaurav.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is correct. Polymorphism applies only to instance methods and not to variables.
 
Tejas Aryan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In short:

variables in java are "early" binded.
methods are "late" binded.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic