C++ language

Single Inheritance
Previous Home Next

Program Of Single Inheritance

#include<stdio.h>
class A
{
int a1,a2;
public :
void getdata()
{
cout<<"\n Enter value of a1 and a2";
cin>>a1>>a2;
}
void putdata()
{
cout<<"\n value of a1 is" <<a1"and a2 is"<<a2;
}

};
class B: public A       //class B is publicly derived by class A
{
int b1,b2;
public :
void indata()
{
cout<<"\n Enter the value of b1 nad b2";
cin>>b1>>b2;
}
};
void main()
{
B b;
b.getdata();         //base class member function
b.indata();          //derived class member function
b.putdata();
b.outdata();
}

Output:

enter value of a1 and a2
2
3
enter  value of b1 and b2
4
5
the value of a1 is 2 and a2 is 3
the value of b1 is 4 and b2 is 5
Previous Home Next