Single inheritance

Definition:

A Derived class with only one base class is called as single inheritence.The older class is called as base class. The new class is called as derived class.

Example:

#include< iostream.h>

class B
{
int a;                                      //private; not inheritable
public:
int b;                                      //public; ready for inheritance
void get_ab();
int get_a(void);
void show_a(void);
};

class D : public B                //public derivation
{
Int c;
public:
void mul(void);
void display(void);
};

void B :: get_ab(void)
{
a=5; b=10;
}

int B :: get_a()
{
return a;
}
void b :: show_a()
{
cout<< “a=”<<a<<”\n”;
}
void D :: mul()
{
c=b* get a();    
}
void D :: display()
{
cout<< “a=”<<get_a()<<”\n”;
cout<< “b=”<<b<<”\n”;
cout<< “c=”<<c<<”\n\n”;
}

Int main()
{
D d;

d.get_ab();
d.mul();
d.show_a();
d.display();

                d.b= 20;
d.mul();
d.display();
return 0;

}

Output

 

 

 

 

Inheritance types by s.kamatchi priyanka