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 abstract class in oop?

765


Can private class be inherited?

938


Why multiple inheritance is not allowed?

842


String = "C++ is an object oriented programming language.An imp feature of oops is classes and objects".Write a pgm to count the repeated words from this scenario?

2175


what are the different types of qualifier in java?

2040


What is meant by multiple inheritance?

965


Write a c++ program to display pass and fail for three student using static member function

3114


What is abstraction with example?

847


is there any choice in opting subjects like 4 out of 7

1950


What is oops with example?

793


What is polymorphism what are the different types of polymorphism?

766


What is object-oriented programming? Webopedia definition

971


What is a null tree?

889


What is polymorphism programming?

875


What is inheritance in oop?

819