What is polymorphism ? Explain with examples

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is abstraction in oops?

578


Why is there no multiple inheritance?

562


What are the benefits of interface?

571


What is abstraction with example?

597


Which method cannot be overridden?

572






What is a class in oop?

593


Describe these concepts: Polymorphism, Inheritance and Abstraction.

604


Why do we use inheritance?

625


What are the three parts of a simple empty class?

1447


Which language is pure oop?

545


What is persistence in oop?

659


What is pointer in oop?

528


What is the renewal class?

2160


can inline function declare in private part of class?

3651


What are constructors in oop?

583