0% found this document useful (0 votes)
8 views

Exp21_virtualfunction

Uploaded by

soham2119
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Exp21_virtualfunction

Uploaded by

soham2119
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

/*Exp21:Define a class parent in which use read function, define another class child use same read function.

Display the data of both the read function on output screen using virtual function.*/
#include<iostream.h>
#include<conio.h>
class parent
{
public:
void virtual read()
{
cout<<"parent class read function"<<endl;
}
};
class child:public parent
{
public:
void read()
{
cout<<"child class read function"<<endl;
}
};
void main()
{
parent p,*pptr;
child c,*cptr;
clrscr();
pptr=&p;
pptr->read();
pptr=&c;
pptr->read();
getch();
}
/*OUTPUT
parent class read function
child class read function
*/

You might also like