Overriding in C++.

Overriding: Overriding function having same name as well as same parameters replace the base class to the derived class(inherited class).

 

Let’s write a program of Method overriding .

 

 

//Code:

 


#include<iostream.h>

#include<conio.h>

class base

{

public:

void display()

{

cout<<” \n base class displaying”;

}

void show()

{

cout<<” \n base class displaying”;

}

};

class derive:public base

{

public:

void display() 

{

cout<<”derive class displaying.”;

}

};

void main()

{

clrscr();

derive t;

t.display();

t.show();

getch();

}

 

 

Now run the following program and see output.

 

 

Output:

 

OUTPUT

 

Happy coding.

 

 

Tags: , ,