wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Inheritance and static methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inheritance and static methods" Watch "Inheritance and static methods" New topic
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: 6109
    
    6

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.




 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inheritance and static methods
 
Similar Threads
Private variable access
static
Getting output of other class.
JavaRanch Rule Round-up Game?
Marcus Green - Exam 2 - Question 9