Explain the different forms of Polymorphism.

From a practical programming viewpoint, polymorphism exists in three distinct forms in Java:
Method overloading
Method overriding through inheritance
Method overriding through the Java interface

Showing Answers 1 - 31 of 31 Answers

Rahul Sen

  • Jul 25th, 2005
 

it is not very clever answer at all.

  Was this answer useful?  Yes

amarjyoti de

  • Aug 4th, 2005
 

the answer does in anyway give a full perspective of olymorphism

  Was this answer useful?  Yes

John

  • Aug 4th, 2005
 

Why don't some one answer in detail insted of comlaining about the level of detail... helps others

  Was this answer useful?  Yes

Paul

  • Aug 4th, 2005
 

Uses of Inheritance 
 
The classic examples of an inheritance hierarchy are borrowed from animal and plant taxonomies. For example, there could a class corresponding to the Pinaceae (pine) family of trees. Its subclasses could be Fir, Spruce, Pine, Hemlock, Tamarack, DouglasFir, and TrueCedar, corresponding to the various genera that make up the family.  
 
The Pine class might have SoftPine and HardPine subclasses, with WhitePine, SugarPine, and BristleconePine as subclasses of SoftPine, and PonderosaPine, JackPine, MontereyPine, and RedPine as subclasses of HardPine. 
There's rarely a reason to program a taxonomy like this, but the analogy is a good one. Subclasses tend to specialize a superclass or adapt it to a special purpose, much as a species specializes a genus. 
 
Here are some typical uses of inheritance: 
 
 
Reusing code. If two or more classes have some things in common but also differ in some ways, the common elements can be put in an a single class definition that the other classes inherit. The common code is shared and need only be implemented once.  
 
For example, Faucet, Valve, and WaterPipe objects, defined for the program that models water use, all need a connection to a water source and they all should be able to record the rate of flow. These commonalities can be encoded once, in a class that the Faucet, Valve, and WaterPipe classes inherit from. A Faucet can be said to be a kind of Valve, so perhaps the Faucet class would inherit most of what it is from Valve, and add very little of its own.  
 
Setting up a protocol. A class can declare a number of methods that its subclasses are expected to implement. The class might have empty versions of the methods, or it might implement partial versions that are to be incorporated into the subclass methods. In either case, its declarations establish a protocol that all its subclasses must follow.  
 
When different classes implement similarly named methods, a program is better able to make use of polymorphism in its design. Setting up a protocol that subclasses must implement helps enforce these naming conventions.  
 
Delivering generic functionality. One implementor can define a class that contains a lot of basic, general code to solve a problem, but doesn't fill in all the details. Other implementors can then create subclasses to adapt the generic class to their specific needs. For example, the Appliance class in the program that models water use might define a generic water-using device that subclasses would turn into specific kinds of appliances.  
 
Inheritance is thus both a way to make someone else's programming task easier and a way to separate levels of implementation.  
 
Making slight modifications. When inheritance is used to deliver generic functionality, set up a protocol, or reuse code, a class is devised that other classes are expected to inherit from. But you can also use inheritance to modify classes that aren't intended as superclasses. Suppose, for example, that there's an object that would work well in your program, but you'd like to change one or two things that it does. You can make the changes in a subclass.  
 
Previewing possibilities. Subclasses can also be used to factor out alternatives for testing purposes. For example, if a class is to be encoded with a particular user interface, alternative interfaces can be factored into subclasses during the design phase of the project. Each alternative can then be demonstrated to potential users to see which they prefer. When the choice is made, the selected subclass can be reintegrated into its superclass.  
 
 
Click here to Complete Book Online

Raju

  • Oct 24th, 2005
 

Different forms of Polymorphism.

  Was this answer useful?  Yes

avinash

  • Nov 7th, 2005
 

different types of polymorphism

1. compile time polymorphism

2.run time polymorphism

  Was this answer useful?  Yes

rekhila.k

  • Nov 15th, 2005
 

1.overriding

2.overloading

kishore

  • Mar 6th, 2006
 

CLient & run time

  Was this answer useful?  Yes

Nitin

  • May 11th, 2006
 

Types of Polymorphism

1. Ad-Hoc Polymorphism

-  If number of forms of object are Fixed/Finite

2. Parametric Polymorphism

-  If number of forms of object are Infinite

  Was this answer useful?  Yes

kavitha

  • Jul 26th, 2006
 

polymorphism -> a form it reacts many forms.

polymorphism are two types

1)compile time polymorphism  : this process can be done in the compile time only.

tow types of the compiletime polymorphism

a)operator overloading

b)function overloading

2)runtime polymorphism : this process can be done in the runtime only. by using pointer to object& virtual funtions and also overriding.

  Was this answer useful?  Yes

Riti

  • Aug 23rd, 2006
 

Different form of polymorphism

1. Overloading:- overriding is more then one functions have the same name with different arguments within a class.

2. Overriding:-overriding is more than one function having the same name with different return type within a class. no of argument can be same

  Was this answer useful?  Yes

Hi,
I can frame some answer for that.

There are Two types of ploymorphisam in C++(As i Know only C++)
1.Compile time Polymorphism
2.Run time ploymorphism.

Compile time polymorphism acheived through Function Overloading and Operator overloading.(This is also called Early binding)
Run time polymorphisam achieved through Virtual Functions.(This is called late binding or Dynamic binding)

  Was this answer useful?  Yes

lehroy

  • Jan 29th, 2008
 

 the different types of polymorphism is -

1. compile time polymorphism

2. run time polymorphism

  Was this answer useful?  Yes

pratap557

  • Feb 7th, 2008
 

Polymorphism By lexical meaning "Same thing having different forms"

In OOPs

Two types of Polymorphism
1.CompileTime 2. Runtime


1. Compile Time
     Operator Overloading
     Function Overloading

     Means You can extend the meaning of the same Operator , Or Function By your desired definition.

    You can add two classes using Opt. Overloading. And acn add Two interger, two string, floats by function Add by multiple definition by you. For outsiders it will show the same name method.

  2. run time
     By declaring a function virtual in base class . we can call the base class function if the child class having the same named function
  In large apllication at runtime the path is determined.

  Was this answer useful?  Yes

It holds more than one form, It has two types : -


1. compile time polymorphism: - That holds the overloading.

2. run time polymorphism: -That holds the overridding.

 

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions