Polymorphism in Java

India
November 16, 2007 5:29am CST
Can one explain what is the difference between CompileTime and RunTime Polymorphism in Java.
1 person likes this
5 responses
• India
25 Jan 09
Polymorphism is a Greek word derived from Polymorphos and meaning of this word is "having many forms". This is the last principle of object oriented programming that allows using one interface for a general class of action. Polymorphism can be applied to data types as well as functions. We can say that it is a facility for same method name to be used in conjunction with various different objects. If we think in another way then we can say that there are multiple implementations of the method and we can select one of them according to our need. Using polymorphism principle in java we can refer subclass object using variable of super class. Polymorphism allows programmer to write codes more abstractly. Programs written in this manner has less redundancy and high efficiency. We can use polymorphism when we are dealing with various methods throughout different classes. For example if we have some classes and some program needs one of the subclasses but this program don't know which subclass to use. So use super class variable pointing it to subclass that we require. Polymorphism is also called dynamic binding or late time binding.
• India
31 Dec 07
Above said is more than enough to explain abt the difference. Give rating , my dear friend
@senthil2k (1500)
• India
30 Nov 07
The very simple answers is as follows: 1) Overriding- Runtime polymorphism 2) Overloading - Compiletime polymorphism HOpe this helps.
@s77937 (3)
• Italy
5 Dec 07
http://www.scottdstrader.com/blog/ether_archives/000546.html
• Italy
21 Dec 07
senthil2k has answered perfectly. I'll explain further what Overriding and Overloading is. Overloading: writing methods with the same name but different signatures (ex with different parameters) Overriding: in a subclass you re define a method that was defined in the superclass. Polymorphism happens at runtime because at runtime the program decides which superclass or subclass a variable is and applies the correct method.