simple program for virtual function?

Answer Posted / shafi . shaik

//The Concepts of interface classes in Java (Function
Overriding
#include<iostream.h>
#include<conio.h>
class A
{
public:
virtual void cal()
{
}
};
class B:public A
{
public:
void cal()
{
cout<<"Addition"<<10+20;
}
};
class C:public A
{
public:
void cal()
{
cout<<"Multiplication"<<10*20;
}
};
void main()
{
clrscr();
A *p;
B ob;
C ob1;
p=&ob;
p->cal();
p=&ob1;
p->cal();
getch();
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can you return multiple values from a function?

856


Is null valid for pointers to functions?

875


Why is c so powerful?

894


Do you know the purpose of 'register' keyword?

838


What is 'bus error'?

882


typedef struct{ char *; nodeptr next; } * nodeptr ; What does nodeptr stand for?

1413


What is #define?

806


What is a node in c?

748


What is static and volatile in c?

1003


Who developed c language?

871


why use functions a) writing functions avoids rewriting the same code over and over b) using functions it becomes easier to write programs and keep track of what they are doing c) a & b d) none of the above

922


Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?

896


What are the advantages and disadvantages of a heap?

948


What is include directive in c?

867


What is c value paradox explain?

812