//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();
}
#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();
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.