aspose file tools
The moose likes Beginning Java and the fly likes How JVM knows to handle Runtime Polymorphism? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "How JVM knows to handle Runtime Polymorphism?" Watch "How JVM knows to handle Runtime Polymorphism?" New topic
Author

How JVM knows to handle Runtime Polymorphism?

sujitha reddy
Greenhorn

Joined: Oct 20, 2006
Posts: 15
How JVM knows to handle Runtime Polymorphism?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56224
    
  13

Not a servlet question. Moved to Java in general.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
I'm not sure I understand your question - I'm inclined to answer "because it was programmed to", but I guess that's not what you want to hear. So please elaborate...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Durgaprasad
Greenhorn

Joined: Oct 02, 2006
Posts: 17
There is something called dynamic dispatcher in the JVM.
In computer science, dynamic dispatch is the process of mapping a message to a specific sequence of code (method) at runtime. This is done to support the cases where the appropriate method cannot be determined at compile-time (i.e. statically). Dynamic dispatch is only used for code invocation and not for other binding processes (such as for global variables) and the name is normally only used to describe a language feature where a runtime decision is required to determine which code to invoke.

Further java uses pointers to adopt dynamic dispatcher.
Each instance will have pointer to the methods and JVM maintains a table to map the objects and the methods
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I'm pretty sure this is right ... somebody jump in if not ... restating roughly what Durgaprasad said ...

In pure dynamic, when you invoke a method on an object instance the runtime has to see if the class of that instance has the method. If not, the runtime has to walk up the inheritance stack and see if some ancestor class has the method. This is common in plenty of languages, very dynamic but relatively expensive. If you can keep all your classes in physical memory for minimal paging it's not too bad.

In Java the runtime goes to the class of the instance and the class has a direct connection to the code that will execute. That connection is built at compile time so there's no exploration of the inheritance stack. It's still runtime polymorphism because the compiler can't hook the caller up to the method because the compiler has no idea what the target object's class will be at runtime.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How JVM knows to handle Runtime Polymorphism?
 
Similar Threads
How JVM knows to handle Runtime Polymorphism?
How to load a Jar Library dynamically?
Is Polymorphism and Late Binding the same or different?
Why isn't this generics based instantiation working?
throw and throws