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 we use classes in oop?
What is the difference between inheritance and polymorphism?
What is an example of genetic polymorphism?
What is the point of oop?
Why is object oriented programming so hard?
write string class as your own class in java without using any built-in function
Why do we use class?
What is polymorphism in oops with example?
What is encapsulation in ict?
class type to basic type conversion
What is difference between abstraction and encapsulation?
How can you overcome the diamond problem in inheritance?
What is multilevel inheritance explain with example?
How do you achieve runtime polymorphism?
Can you inherit a private class?