Monday, April 5, 2021

function overriding (OOP) (31)

       /*function overriding

*********************/

/*Define any function in both base class and derived class with same return type, same name, same 

parameter list this concept is called function overriding.there are some requirments for function 

overriding.inheritance should be there.function overriding cannot be done within a class. for 

this we require a base class and derieved class.  */

#include<iostream>

using namespace std;

class Base

{

public:

void show()

{

cout<<"Base class"<<endl;

}

};

class Derived:public Base

{

public:

void show()

{

cout<<"Derived class"<<endl;

}

};

int main()

{

Base *b;

Derived d;

b=&d;

b->show(); //early binding occure

// b.show();//early binding occure

// d.show(); 

}

No comments:

Post a Comment