PROGRAM TO IMPLEMENT FUNCTION OVERRIDING IN CLASSES

/*PROGRAM TO IMPLEMENT FUNCTION OVERRIDING IN CLASSES*/

#include<conio.h>

#include<iostream.h>

class base

{

int a;

public:

void input()

{

cout<<“Enter a: “;

cin>>a;

}

void show()

{

cout<<“a=”<<a<<endl;

}

};

class derived:public base

{

int a;

public:

void input()

{

cout<<“Enter a: “;

cin>>a;

}

void show()

{

cout<<“a= “<<a<<endl;

}

};

void main()

{

clrscr();

cout<<“Base class functions are executed”<<endl;

base b1;

b1.input();

b1.show();

cout<<“Base class functions are overridden in derivede class”<<endl;

derived d1;

d1.input();

d1.show();

getch();

}

Leave a Reply

Your email address will not be published. Required fields are marked *