C++ language

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

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: