What is polymorphism ? Explain with examples

Answers were Sorted based on User's Feedback



What is polymorphism ? Explain with examples..

Answer / nisha

Polymorphism means one name,many properties.Example of
polymorphism is function overloading whare we can have many
functions with same name but having different properties
like the number of arguments in the function header.

Is This Answer Correct ?    43 Yes 8 No

What is polymorphism ? Explain with examples..

Answer / k.r.sukumar

Polymorphism means "A single function which is used for
different purposes depending upon the parameters passed"

for eg;
Area is the function name which is used for
calculating areas of the rectangle, triangle and even more.
from this persepective we conclude that area is the single
function which is used for calculating different ones.
area(a);---> Area of the square

area(l,b);---> Area of the rectangle.

Is This Answer Correct ?    22 Yes 1 No

What is polymorphism ? Explain with examples..

Answer / danneel

The previous example is overloading not polymorphism.

Polymorphism is multiple classes having the same method -
for example - a DOG and CAT class that are sub classes of
ANIMAL - ANIMAL has a virtual function - SPEAK. DOG
implements speak via System.out.println("WOOF") and CAT
implements it as System.out.println("MEOW") then

ANIMAL anim = null;
anim = New DOG();
anim.speak();
anim = New CAT();
anim.speak()

will each put out the appropriate string.

Is This Answer Correct ?    18 Yes 3 No

What is polymorphism ? Explain with examples..

Answer / khushpreet kaur.

Polymorphism is taken from the greek word which means "many
forms"...
So polymorphism means "to carry out operations of
different processing steps by function having same
messages".
when a base class member function can be overridden by
defining a derived class member function with same name as
that of the base class member function,then such type of
concept is called "Polymorphism".(one interface multiple
methods)
polymorphism is of two types- compile time(early or static
binding) and run time(dynamic or late binding)..
in comlite time is of two types-function overloading and
operator overloading.
in run time is of two types-virtual function and pure
virtual function..

Is This Answer Correct ?    11 Yes 0 No

What is polymorphism ? Explain with examples..

Answer / ashok kumar

polymorphism means many forms,greekword-poly-many fuction
overloding,fuction overloding,operator overloding.
ex->'+'
this opertor can be overloaded to add strings
(concatenation)or sets(union)and so on. functions also can
be overloaded as show in the next sectin.the
terms 'Overloading'and 'polymorphism' are used
interchangeablely.

Is This Answer Correct ?    10 Yes 3 No

What is polymorphism ? Explain with examples..

Answer / selvi

Polymorphism means one in many forms.It describes a method
in different characteristics. A method gets differentiated
by its Function signature. Function signatures are
datatypes, Number of parameters used in method. For
example, a method called Calculation has different
character such as add, sub, mul, div, etc.

Is This Answer Correct ?    10 Yes 3 No

What is polymorphism ? Explain with examples..

Answer / manjeet

POLYMORPHISM is derived from two latin words poly(means-
many) and morphs(means-forms).this concept of OOPS provides
one function to be carried out in several ways or on
several object types.
working:-The polymorphism is the ability of responding
different object in there own way to a particular
message.so,when message is sent requesting an object to do
particular function,the message names the function the
object should perform.beacause diffrent objects can have
different functions with same name,the meaning of the
message must be decided with respect to the particular
object that recieved the message.so,the same message sent
to two different objects can invoke two different functions.

example:-If a brazilian is commanded to speak(),he/she may
speak portuguese. However, if a indian is commanded to speak
(), he/she may speak hindi. They both inherit speak() from
human, but their Subclass methods override the methods of
the Superclass; this is Overriding Polymorphism and
Inheritance. Adding a walk class to human would give both
indian and brazilian object's the same walk method.

// Assembly: Common Classes
// Namespace: CommonClasses

public interface Ihuman
{
string Name
{
get;
}
string Talk();
}

// Assembly: human
// Namespace: human

public class humanBase
{
private string _name;
AnimalBase(string name)
{
_name = name;
}
public string Name
{
get
{
return _name;
}
}
}

// Assembly: human
// Namespace: human

public class indian : humanBase, Ihuman
{
public indian(String name) :
base(name)
{
}

public string Talk() {
return "hindi!";
}
}

// Assembly: human
// Namespace: human

public class brazil : humanBase, Ihuman
{
public brazil(string name) :
base(name)
{
}

public string Talk() {
return "portuguese";
}
}

// Assembly: Program
// Namespace: Program
// References and Uses Assemblies: Common Classes, human

public class Testhuman
{
// prints the following:
//
// ram: hindi!
// Mr. harsh: hindi!
// Lara: portuguese!
//
public static void Main(String[] args)
{
List<Ihuman> human = new List<Ihuman>();
human.Add(new indian("ram"));
human.Add(new indian("Mr. harsh"));
human.Add(new brazilian("Lara"));

foreach(Ihuman human in human)
{
Console.WriteLine(human.Name + ": " +
human.Talk());
}
}
}

Is This Answer Correct ?    8 Yes 1 No

What is polymorphism ? Explain with examples..

Answer / jun jitendra

"Poly" means "many" and "morph" means "form". Polymorphism is the ability of an object (or reference) to assume (be replaced by) or become many different forms of object. Example: function overloading, function overriding, virtual functions. Another example can be a plus ‘+’ sign, used for adding two integers or for using it to concatenate two strings.
//method hiding in polymorphism
using System;
namespace Polymorphism
{
class A
{
public void Foo() { Console.WriteLine("A::Foo()"); }
}

class B : A
{
public new void Foo() { Console.WriteLine("B::Foo()"); }
}

class Test
{
static void Main(string[] args)
{
A a;
B b;

a = new A();
b = new B();
a.Foo(); // output --> "A::Foo()"
b.Foo(); // output --> "B::Foo()"

a = new B();
a.Foo(); // output --> "A::Foo()"
}
}
}

Is This Answer Correct ?    4 Yes 0 No

Post New Answer

More OOPS Interview Questions

What is virtual class and friend class?

5 Answers   IBS, Intel, Wipro,


what is an qt4 interface?

1 Answers   IBM,


What is the expansion of OOPS?

24 Answers   TCS,


What is encapsulation with real life example?

0 Answers  


what are the ways in which a constructors can be called?

2 Answers   TCS,






Can we have a private constructor ?

12 Answers   HSBC, Ness Technologies, TCS, Wipro,


What is extreme programming?

2 Answers  


What are the 4 main oop principles?

0 Answers  


What are classes oop?

0 Answers  


What is difference between function overloading and overriding?

1 Answers   emc2,


which structured data type is not used in c++? 1.union 2.structure 3.string 4.boolean

2 Answers   HCL, Wipro,


What is the correct syntax for inheritance? 1) class aclass : public superclass 2) class aclass inherit superclass 3) class aclass <-superclass

6 Answers   Wipro,


Categories