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

What is C language ?

0 Answers   Jekson,


What are the different types of errors?

0 Answers  


Is c is a high level language?

0 Answers  


Explain what is the benefit of using enum to declare a constant?

0 Answers  


How to use c/c++ code in JAVA

10 Answers   CDAC, IBM, Satyam, Scope International,






what is the use of call back function in c?tell me with example

2 Answers   Bosch,


Write a program with dynamically allocation of variable.

0 Answers   Atos Origin,


Write a program to add the following ¼+2/4+3/4+5/3+6/3+... (Like up to any 12 no.s)

1 Answers   HTC,


why we use pointer in c

7 Answers   HCL, TCS,


Explain how do you sort filenames in a directory?

0 Answers  


what is stack , heap ,code segment,and data segment

0 Answers  


What is RAM memory? and What is ROM?Who designed one is temparary and another is permanent?why they designed like that?By using far pointer which type data(whether hexadecimal)we can access?

1 Answers   Excel,


Categories