Program to check the imortance of virtual function or late binding for the implementation of the inheritance to get required output according to the given access(by using virtual).

# include
# include
class B
{
public :
virtual void show ( )
{
cout <<" nThis is in class B " ;
}
} ;
class D1 : public B
{
public :
void show ( )
{
cout <<" nThis is in class D1 " ;
}
} ;
class D2 : public B
{
public :
void show ( )
{
cout <show () ;
P = & obj1 ;
P -> show () ;
P = & obj2 ;
P -> show () ;
getch () ;
}

Leave a Reply

Your email address will not be published. Required fields are marked *