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

write knight tour problem which is present in datastructure

2164


What are the 5 oop principles?

603


What is the difference between abstraction and polymorphism?

617


Will I be able to get a picture in D drive to the c++ program? If so, help me out?

1657


Why is oop better than procedural?

604






#include #include #include #include void select(char *items, int count); int main(void) { char s[255]; printf("Enter a string:"); gets(s); select(s, strlen(s)); printf("The sorted string is: %s.\n", s); getch(); return 0; } void select(char *items, int count) { register int a, b, c; int exchange; char t; for(a = 0; a < count-1; ++a) { exchange = 0; c = a; t = items[ a ]; for(b = a + 1; b < count; ++b) { if(items[ b ] < t) { c = b; t = items[ b ]; exchange = 1; } } if(exchange) { items[ c ] = items[ a ]; items[ a ] = t; } } } design an algorithm for Selection Sort

2068


What is the important feature of inheritance?

635


Can we create object of abstract class?

577


Which method cannot be overridden?

578


Where is pseudocode used?

565


i am getting an of the type can not convert int to int *. to overcome this problem what we should do?

1837


Is this job good for future? can do this job post grduate student?

1694


What is pure oop?

597


What is encapsulation and abstraction? How are they implemented in C++?

637


What are the advantages of polymorphism?

577