Method Overriding in C++
If we inherit a class into the derived class and provide a
definition for one of the base class's function again inside the derived class,
then that function is said to be overridden, and this mechanism is
called Function Overriding.
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()
{
BaseClass obj=DerivedClass();
obj.disp();
getch();
}
No comments:
Post a Comment