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
Joined: Oct 02, 2006
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
Joined: Jan 29, 2003
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