simple program for virtual function?



simple program for virtual function?..

Answer / 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

More C Interview Questions

1)what are limitations for recursive function? 2)write a program to read a text file and count the number of characters in the text file

1 Answers  


write an interactive program to generate the divisors of a given integer.

7 Answers   TCS,


What are the 5 types of organizational structures?

0 Answers  


Reverse a string word by word??

9 Answers  


What are different types of operators?

0 Answers  






What are the similarities between c and c++?

0 Answers  


How can I set an array's size at run time?

9 Answers  


f(*p) { p=(char *)malloc(6); p="hello"; return; } main() { char *p="bye"; f(p); printf("%s",p); } what is the o/p?

7 Answers   Hughes,


Explain what will be the outcome of the following conditional statement if the value of variable s is 10?

0 Answers  


Why can arithmetic operations not be performed on void pointers?

0 Answers  


How can I remove the trailing spaces from a string?

0 Answers   Aspire,


main() { printf("hello"); fork(); }

0 Answers   Wilco,


Categories