C++ language

adplus-dvertising
A Program For Single Inheritance
Previous Home Next
#include<iostream.h>
Class A
{
int a,b;
public :
void getdata()
	{
cout<<
"\n Enter the value of a and b";
cin>>a>>b;
}
void putdata()
{
cout<<
"\n The value of a is :"<<a<<
"and b :"<<b;
}
};
class B : public 
A   //class  is publicly derived from A
{
int c,d;
public :
void intdata()
{
cout<<
"\n Enter the value of c and d :";
cin>>c>>d;
}
void outdata()
{
cout<<
"\n The value of c ;"<<c<<
"and d :"<<d;
}
};
void main()
{
B obj;
obj.getdata();    //base class member function
obj.indata();      //derived class member function
obj.putdata();
obj.outdata();
}

Output:

Enter the value of a and b
2
3
Enter the value of c and d
4
5
The value of a is 2 and b is 3
The value of c is 4 and d is 5
Previous Home Next