Multiple inheritance
 A PROGRAMMING TECHNIQUE THAT IS USED TO
REUSE AN EXISTING CLASS TO BUILD A NEW CLASS
IS KNOWN AS INHERITANCE.
Inheritance Access Specifiers
 Private Inheritance
In private mode the public and protected
members of Base class become private
members of Derived class.
class B : private A
class C : private B
Inheritance Access Specifiers
 Public Inheritance
This inheritance mode is used mostly. In this the
protected member of Base class becomes
protected members of Derived class and public
becomes public.
class B : public A
class C : public B
Inheritance Access Specifiers
Protected Inheritance
In protected mode, the public and
protected members of Base class becomes
protected members of Derived class.
class B : protected A
class C : protected B
TYPES OF INHERITANCE
Multiple inheritance
 A type of inheritance in which a derived class inherit
multiple bases classes Is known as multiple
inheritance. In multiple inheritance the derived class
combines the members of all base classes.
Syntax
Class child_class : spec parent_class1, spec parent class2
{
Body of the class
}
 Class A
 {
 body of the class
 };
 Class B
 {
 Body of the class
 };
 Class C : Public A, public B
 {
 Body of the class
 };
#include<iostream.h>
Using namespace std;
Class A
{
protected:
Int a;
Public:
Void in ()
{
cout<<“Enter a:”;
cin>>a;
}
Void out ()
cout<<“The value of a is:”<<a<<endl;
}
};
Class B
{
protected:
Int b;
Public:
Void input ()
{
cout<<“Enter b:”;
cin>>b;
}
Void output ()
{
cout<<“The value of b is:”<<b<<endl;
}
};
Class C : public A, Public B
{
Private:
Int c;
Public:
Void get ()
{
A::in();
B::input();
cout<<“Enter c:”;
cin>>c;
}
Void show ()
{
A::out();
B::output();
cout<<“The value of is c:”<<c<<endl;
}
};
int main ()
{
C obj;
obj.get();
obj.show();
return 0;
}
Out put
Enter a: 1
Enter b: 2
Enter c: 3
The value of a is: 1
The value of b is: 2
The value of c is: 3

Programming presentation

  • 1.
  • 2.
     A PROGRAMMINGTECHNIQUE THAT IS USED TO REUSE AN EXISTING CLASS TO BUILD A NEW CLASS IS KNOWN AS INHERITANCE.
  • 4.
    Inheritance Access Specifiers Private Inheritance In private mode the public and protected members of Base class become private members of Derived class. class B : private A class C : private B
  • 5.
    Inheritance Access Specifiers Public Inheritance This inheritance mode is used mostly. In this the protected member of Base class becomes protected members of Derived class and public becomes public. class B : public A class C : public B
  • 6.
    Inheritance Access Specifiers ProtectedInheritance In protected mode, the public and protected members of Base class becomes protected members of Derived class. class B : protected A class C : protected B
  • 7.
  • 8.
    Multiple inheritance  Atype of inheritance in which a derived class inherit multiple bases classes Is known as multiple inheritance. In multiple inheritance the derived class combines the members of all base classes.
  • 9.
    Syntax Class child_class :spec parent_class1, spec parent class2 { Body of the class }
  • 10.
     Class A {  body of the class  };  Class B  {  Body of the class  };  Class C : Public A, public B  {  Body of the class  };
  • 11.
    #include<iostream.h> Using namespace std; ClassA { protected: Int a; Public: Void in () { cout<<“Enter a:”; cin>>a; }
  • 12.
    Void out () cout<<“Thevalue of a is:”<<a<<endl; } }; Class B { protected: Int b; Public: Void input () { cout<<“Enter b:”; cin>>b; }
  • 13.
    Void output () { cout<<“Thevalue of b is:”<<b<<endl; } }; Class C : public A, Public B { Private: Int c; Public: Void get () { A::in(); B::input(); cout<<“Enter c:”; cin>>c; }
  • 14.
    Void show () { A::out(); B::output(); cout<<“Thevalue of is c:”<<c<<endl; } }; int main () { C obj; obj.get(); obj.show(); return 0; }
  • 15.
    Out put Enter a:1 Enter b: 2 Enter c: 3 The value of a is: 1 The value of b is: 2 The value of c is: 3