This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes public Class variables and inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "public Class variables and inheritance" Watch "public Class variables and inheritance" New topic

public Class variables and inheritance

Tejas Aryan

Joined: Apr 12, 2009
Posts: 22
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..

Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

That is correct. Polymorphism applies only to instance methods and not to variables.

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Tejas Aryan

Joined: Apr 12, 2009
Posts: 22
In short:

variables in java are "early" binded.
methods are "late" binded.
I agree. Here's the link:
subject: public Class variables and inheritance
It's not a secret anymore!