| Author |
Inheritance and static methods
|
sovan chatt
Ranch Hand
Joined: Aug 09, 2010
Posts: 43
|
|
The output of the code is h1 h4;so,the p1 method calls parent class's P() method and child class's P2() method.Which I feel is very confusing.What is the general concept?
|
 |
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 5829
|
|
The only thing that is runtime polymorphic in Java is a non-private, non-static, non-final method.
In other words, if a method is non-private, non-static, and non-final, then the JVM will decide at runtime which class's implementation of that method to call, based on the runtime class of the object.
For all other methods--all methods that are either private, static, or final (or any combination)--the compiler determines which class's implementation to call, based on the compile-time type of the reference.
|
 |
 |
|
|
subject: Inheritance and static methods
|
|
|