Function Overriding In C++
Function overriding is a feature that allows us
to have a same function in child class which is already present in the parent
class. A child class inherits the data members and member functions of parent
class, but when you want to override a functionality in the child class then
you can use function overriding.
Fig: Function Overriding In C++ |
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
class BaseClass()
{
public:
void disp()
{
Cout<<”function of parent class”;
}
};
class
DerivedClass: public BaseClass
{
public:
void disp()
{
cout<<”function of child class”;
}
};
void main()
{
DerivedClass
obj=DerivedClass();
obj.disp();
getch();
}
Output:
Function of child class.
No comments:
Post a Comment