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

There is a practice in coding to keep some code blocks in comment symbols than delete it when debugging. How this affect when debugging?

0 Answers  


Explain data types & how many data types supported by c?

0 Answers  


What is structure of c program?

0 Answers  


What is function pointer and where we will use it

2 Answers   Infosys, NetApp,


int i[2], j; int *pi;i[0] = 1; i[1] = 5; pi = i; j = *pi + 1 + *(pi + 1)Value of j after execution of the above statements will be a) 7 b) 6 c) 4 d) pointer

0 Answers  






void main(int argc,char *argv[],char *env[]) { int i; for(i=1;i<argc;i++) printf("%s",env[i]); }

3 Answers  


Give a method to count the number of ones in a 32 bit number?

4 Answers  


what is the value of 'i'? i=strlen("Blue")+strlen("People")/strlen("Red")-strlen("green")

7 Answers   Cadence, JNTU, Zen Technologies,


program for following output using for loop? 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5

8 Answers   Aptech, Infosys,


What is this pointer in c plus plus?

0 Answers  


Describe for loop and write a c program to sum the series X + x2/2! + x3 /3! + …….. up to fifteen terms.

2 Answers  


What are the advantages of using new operator as compared to the function malloc ()?

0 Answers   NIIT,


Categories