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 are the components of marker interface?

799


why reinterpret cast is considered dangerous?

2108


What is difference between inheritance and polymorphism?

776


What is abstraction in oops?

790


What is encapsulation with real life example?

787


Can we override main method?

839


What is variable example?

786


hi all..i want to know oops concepts clearly can any1 explain??

1890


Can static class have constructor?

786


Can a varargs method be overloaded?

812


How to use CMutex, CSemaphore in VC++ MFC

4537


Write a program to sort the number with different sorts in one program ??

2110


What is abstraction example?

832


what type of question are asked in thoughtworks pair programming round ?

1964


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

2377