Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

What is Polymorphism?!!

Tue Jul 03, 2007 11:55 pm

What is Polymorphism?
----------------------------


Polymorphism gives us the ultimate flexibility in extensibility. Polymorphism is a term that describes a situation where one name may refer to different methods. In java there are two type of polymorphism: overloading type and overriding type.

When you override methods, java determines the proper methods to call at the programs run time, not at the compile time. Overriding occurs when a class method has the same name and signature as a method in parent class. Overloading occurs when several methods have same names with different method signature. Overloading is determined at the compile time.

Example: Overloading

java code
Class Book{
String title;
String publisher;
float price;
setBook(String title){
}
setBook(String title, String publisher){
}
setBook(String title, String publisher,float price){
}
}


Example: Overriding

java code
Class Tool{
void operate_it(){
// implementation here.
}
}
Class ScrewDriver extends Tool{
void operate_it(){
// implementation here.
}
}




Post a reply
  Related Posts  to : What is Polymorphism?!!
 polymorphism     -  
 run time polymorphism     -  
 Inheritance & polymorphism checker code     -  

Topic Tags

Java OOP