0% found this document useful (0 votes)
128 views2 pages

Function Overriding

Function overriding allows a derived class to provide a new implementation of a method defined in the base class. The signature, including the number, type, and sequence of arguments, must be the same for the method in the derived class. An example demonstrates a Display() method being overridden in the derived class to change its output while the Show() method is inherited from the base class without change.

Uploaded by

Ashutosh Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views2 pages

Function Overriding

Function overriding allows a derived class to provide a new implementation of a method defined in the base class. The signature, including the number, type, and sequence of arguments, must be the same for the method in the derived class. An example demonstrates a Display() method being overridden in the derived class to change its output while the Show() method is inherited from the base class without change.

Uploaded by

Ashutosh Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Function overriding

Giving new implementation of base class method into derived class is called function overriding.

Signature of base class method and derived class must be same. Signature involves:

 Number of arguments
 Type of arguments
 Sequence of arguments

Example of function overriding

#include<iostream.h>
#include<conio.h>

class BaseClass
{

public:

void Display()
{
cout<<"\n\tThis is Display() method of BaseClass";
}

void Show()
{
cout<<"\n\tThis is Show() method of BaseClass";
}

};

class DerivedClass : public BaseClass


{

public:

void Display() //overriding method - new


working of
{ //base class's
display method
cout<<"\n\tThis is Display() method of DerivedClass";
}

};

void main()
{

DerivedClass Dr;

Dr.Display();
Dr.Show();
}

Output :

This is Display() method of DerivedClass


This is Show() method of BaseClass

You might also like