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
Why is polymorphism needed?
Why is oop better than procedural?
What is encapsulation in simple terms?
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
What does it mean when someone says I oop?
why reinterpret cast is considered dangerous?
Why is abstraction needed?
what are the realtime excercises in C++?
What does and I oop and sksksk mean?
How oops is better than procedural?
How do you answer polymorphism?
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!!!)
write a C++ program for booking using constructor and destructor.
Why is encapsulation used?
How do you achieve polymorphism?