This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Regarding Polymorphism 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 » Java in General
Bookmark "Regarding Polymorphism" Watch "Regarding Polymorphism" New topic
Author

Regarding Polymorphism

Rick Charles
Greenhorn

Joined: Jul 27, 2006
Posts: 25
How would you explain Compile time and Runtime polymorphism? And also can someone explain me about dynamic dispatch?
[ April 11, 2007: Message edited by: Rick Charles ]
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

Polymorphism:
Definition of Richard G. Baldwin (His Introductory Java Programming Tutorial will get you started):
compile-time polymorphism: method overloading
runtime polymorphism: method overriding and inheritance

Dynamic dispatch is explained in wikipedia.

Regards, Jan
[ April 11, 2007: Message edited by: Jan Cumps ]

OCUP UML fundamental and ITIL foundation
youtube channel
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38044
    
  22
Sounds more like a beginner's question to me.

I thought polymorphism was only seen at runtime. You will find lots of examples. Imagine you have a superclass, and you have subclasses; they can have methods which have the same signature (overridden) which use different operations. Example:-At compile time all the compiler will notice is that each of these three concrete classes extends Shape, and has a getArea() method. Also that the return types are compatible (in this case all the same, double).
Now, at runtime, you can create different subclasses of Shape:Your compiler can't tell whether you will enter 1 for Circle or 2 for Square or 3 for Triangle. But each has a getArea() method which the JVM finds and uses at Runtime.

try it
 
wood burning stoves
 
subject: Regarding Polymorphism
 
Similar Threads
Does Overloading exhibits Polymorphism behaviour?
Polymorphism
polymorphism
Polymorphism
Polymorphism