#include<iostream.h>
#include<conio.h>
class A
{
public:
virtual void show() //this function enables us to execute different functions by the same function call
{
cout<<"parent class A: ";
}
};
class B:public A
{
public:
void show()
{
cout<<"child class B: ";
}
};
class C:public A
{
public:
void show()
{
cout<<"child class C: ";
}
};
void main()
{
A obj1;
B obj2;
C obj3;
A * ptr;
ptr = & obj1; //ampercent is used to access address of variable and store in a pointer
ptr -> show();
ptr = & obj2;
ptr -> show();
ptr= & obj3;
ptr -> show();
getch();
}
#include<conio.h>
class A
{
public:
virtual void show() //this function enables us to execute different functions by the same function call
{
cout<<"parent class A: ";
}
};
class B:public A
{
public:
void show()
{
cout<<"child class B: ";
}
};
class C:public A
{
public:
void show()
{
cout<<"child class C: ";
}
};
void main()
{
A obj1;
B obj2;
C obj3;
A * ptr;
ptr = & obj1; //ampercent is used to access address of variable and store in a pointer
ptr -> show();
ptr = & obj2;
ptr -> show();
ptr= & obj3;
ptr -> show();
getch();
}
A virtual operate or virtual methodology is a vital a part of the polymorphic portion of object-oriented programming (OOP). A virtual operate permits a derived category to override functions in categories it inherits from – even once the derived category is forged because the style of object from that it inherits.
ReplyDeleteThe Equation
Thanks!Henry jorden
Deletefor sharing good and informative knowledge to others!
keep sharing knowledge with other!