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

Why is polymorphism needed?

605


Why is oop better than procedural?

606


What is encapsulation in simple terms?

542


Why can't we have instance(stack) of a class as a member of the same class like eg.Class A{A obj;} as we can have self refential pointer

1624


What does it mean when someone says I oop?

587






why reinterpret cast is considered dangerous?

1906


Why is abstraction needed?

571


what are the realtime excercises in C++?

2337


What does and I oop and sksksk mean?

655


How oops is better than procedural?

594


How do you answer polymorphism?

580


Write a C++ program without using any loop (if, for, while etc) to print prime numbers from 1 to 100 and 100 to 1 (Do not use 200 print statements!!!)

1643


write a C++ program for booking using constructor and destructor.

2055


Why is encapsulation used?

579


How do you achieve polymorphism?

618