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

Explain what is the most efficient way to store flag values?

0 Answers  


what is the advantage of software development

1 Answers  


the maximum length of a character constant can be a) 1 character b) 8 characters c) 256 chaacters d) 125 characters

0 Answers  


What is the difference between strcpy() and memcpy() function in c programming?

0 Answers  


Can u return two values using return keyword? If yes, how? If no, why?

7 Answers  






#include<stdio.h> #include<conio.h> void main() { float a; clrscr(); a=0.5; if(a==0.5) printf("yes"); else printf("no"); getch(); }

9 Answers   TCS,


what is the difference between const volatile int i & volatile const int j;

2 Answers   HCL,


What are c identifiers?

0 Answers  


Where static variables are stored in c?

0 Answers  


write a program to swap two numbers without using temporary variable?

3 Answers  


What is the difference between fread buffer() and fwrite buffer()?

0 Answers  


Is null valid for pointers to functions?

0 Answers  


Categories