SlideShare a Scribd company logo
INHERITANCE
SESSION 1
SHIJITHA A S
CONTENTS
 Introduction
 Access specifiers and inheritance
 Types of inheritance
 Virtual base class
 Abstract classes
 Advantages & disadvantages - inheritance
2
3
Grand Parents
PARENT 1 PARENT 2
CHILD 11 CHILD 12 CHILD 21 CHILD 22
PARENT – CHILD RELATIONSHIP
INTRODUCTION
 INHERITANCE - An essential characteristics of object oriented programming.
 Existing classes are main components.
 New classes are created from existing class.
 i.e. properties of existing class are extended to new class.
 Existing classes are called BASE CLASS.
 Newley created classes are called DERIVED CLASS.
 Definition : The procedure of creating a new class from one or more existing
classes is termed as inheritance.
 Relationship between base and derived class is known as KIND OF
RELATIONSHIP.
 Accessibility : Object of derived class can access members of base class as well as
derived class, but object of base class cannot access members of derived classes.
4
5
MEMBER A
MEMBER B
MEMBER A
MEMBER B
MEMBER C
MEMBER D
BASE
CLASS
DERIVED CLASS
 REUSABILITY :It means the reuse of properties of base class in the derived
class.
 Reusability is achieved using inheritance.
 Base class is also called as : super class, parent class or ancestor class
 Derived class is also called as sub class, child class or descendent class.
 A class can be derived for more than one class and also it is possible to
derive a class from previously derived class.
6
7
MEMBER A
MEMBER B
MEMBER A
MEMBER B
MEMBER B
MEMBER C
BASE
CLASS
DERIVED CLASS
DERIVED CLASS
MEMBER A
MEMBER C
MEMBER D
ACCESS SPECIFIERS AND INHERITANCE
 Access specifiers : public, private and protected.
 Public: object can access the public members of the class
 Private: object cannot access the private members of the class
 Protected: only object of derived class can access the protected members of the
base class
Syntax :
class_name of derived class : access specifier name of base_class
{
…………
………….
………….
};
8
e.g.
(1) Class B : public A
{
//members of class B
};
Here class A – base class, class B --- derived
class which is derived publicly.
 Object of class B can access all the public
members of class A.
(2) Class B : private A //private derivation
{
//members of class B
};
Here class A – base class, class B --- derived
class which is derived privately.
(3) Class B : A //by default private
derivation
{
//members of class B
};
Here class A – base class, class B --- derived class
which is derived privately.
(4) Class B : protected A //protected
derivation
{
//members of class B
};
Here class A – base class, class B --- derived class
which is derived protected.
9
 When class is derived publicly, then all the public members of the base class can be
accessed directly in the derived class and it cannot access the private members of
the base class.
10
PUBLIC INHERITANCE
Public members
Private members
OBJECT
Base class Derived class
PUBLIC INHERITANCE
e.g.
Class A
{
public:
int x;
};
Class B : public A //derived class
{
public :
int y;
};
Void main()
{
B b;
b.x = 20;
b.y = 30;
cout<<“n Member of A : “<<b.x;
cout<<“n Member of B : “<<b.y;
}
Output :
Member of A :20
Member of B :30
11
 Object of privately derived class cannot directly access the public members of base
class
 Thus member functions are used to access members
12
PRIVATE INHERITANCE
Public members
OBJECT
Base class Derived class
Public members
functions
Private members
PRIVATE INHERITANCE
e.g.
Class A
{
public:
int x;
};
Class B : private A //derived class
{
public :
int y;
B( ) //constructor
{
x = 20;
y = 40;
}
void show( )
{ cout<<“n X= “<<x;
cout<< “n Y= “<<y;
}
};
Void main()
{
B b; //object creation
b . show( );
}
Output :
X =20
Y=40
13
 Object of privately derived class cannot directly access the public members of base
class
 Thus member functions are used to access members
14
PROTECTED INHERITANCE
Public members
OBJECT
Base class Derived class
Public members
functions
Private members
PROTECTED INHERITANCE
e.g.
Class A
{
public:
int x;
};
Class B : private A //derived class
{
public :
int y;
B( ) //constructor
{
x = 20;
y = 40;
}
void show( )
{ cout<<“n X= “<<x;
cout<< “n Y= “<<y;
}
};
Void main()
{
B b; //object creation
b . show( );
}
Output :
X =20
Y=40
15
TYPES OF INHERITANCE
1) Single Inheritance
2) Multiple Inheritance
3) Hierarchical Inheritance
4) Multilevel Inheritance
5) Hybrid Inheritance
6) Multipath Inheritance
16
SINGLE INHERITANCE
 Only one class is derived from a single class
 Further the derived class is not used as a base class.
 Newley created class receives entire characteristics of base class.
17
Class ABC Base class
Class abc Derived class
class Vehicle //base class
{
public:
void show()
{
cout<< "This is a Vehicle";
}
};
class Car : public Vehicle //derived
{
public:
void print()
{
cout<< "This is a Car";
}
};
18
Void main()
{
Car obj;
obj.show();
obj.print();
}
OUTPUT:
This is a Vehicle
This is a Car
Class Vehicle
Class Car
MULTIPLE INHERITANCE
 A class is derived from more than one base classes
19
Class A
Class E Derived class
Class B Class C
20
Class Vehicle
Class Car Derived class
Class Four_wheeler
Base classes
class Vehicle //base
{
public:
void show()
{
cout<< "This is a Vehicle";
}
};
class Four_Wheeler //base
{
public:
void display()
{
cout<< "This is a Four wheeler";
}
};
21
class Car : public Vehicle, Four_wheeler
{
public:
void print()
{
cout<< "This is a Car";
}
};
Void main()
{
Car obj;
obj.show();
obj.display();
obj.print();
}
OUTPUT:
This is a Vehicle
This is a Four wheeler
This is a Car
HIERARCHICAL INHERITANCE
 A- Base class, B,C & D derived
 Further B,C & D are not used for deriving classes
22
Class A
Class C
Class B Class D
23
Class Vehicle
Class Bus
Derived class
Class Car
Base classes
class Vehicle
{
public:
void show()
{
cout<< "This is a Vehicle";
}
};
class Car : public Vehicle
{
public:
void display()
{
cout<< "This is a Car";
}
};
24
class Bus : public Vehicle
{
public:
void print()
{
cout<< "This is a Bus";
}
};
Void main()
{
Car obj1;
Bus obj2;
obj1.show();
obj1.display();
obj2.show();
obj2.print();
}
OUTPUT:
This is a Vehicle
This is a Car
This is a Vehicle
This is a Bus
MULTILEVEL INHERITANCE
 A- Base class, B derived from A , C- derived form C
 C inherits all the features of A & B.
25
Class A
Class C
Class B
Base class1
Base class2
26
Class Vehicle
Class Four_Wheeler
Class Car
Base class1
Base class2
Derived class
class Vehicle
{
public:
void show()
{
cout<< "This is a Vehicle";
}
};
class Four_Wheel: public Vehicle
{
public:
void display()
{
cout<< "This is a Car";
}
};
27
class Car : public Four_wheel
{
public:
void print()
{
cout<< "This is a Bus";
}
};
Void main()
{
Car obj1;
Bus obj2;
obj1.show();
obj1.display();
obj2.show();
obj2.print();
}
OUTPUT:
This is a Vehicle
This is a Car
This is a Vehicle
This is a Bus
HYBRID INHERITANCE
 A- Base class, B derived from A , Class D - derived form B & C
 D inherits all the features of B & C directly and inherits features of class A indirectly
through B
28
Class A
Class D
Class B
Base class
Class C
Derived class
29
Class Vehicle
Class Four_Wheeler
Class Bus
Class Fare
Base classes
Derived classes
class Vehicle
{
public:
void show()
{
cout<< “This is a Vehicle";
}
};
class Four_Wheel: public Vehicle
{
public:
void display()
{
cout<< "This is a Four_Wheeler";
}
};
class Fare
{
public:
void dip()
{
cout<< “Fare is high";
}
};
30
class Bus : public Four_wheel, Fare
{
public:
void print()
{
cout<< “This is a Bus";
}
};
Void main()
{
Bus obj;
obj.print();
obj.dip();
obj.display();
obj.show();
}
OUTPUT:
This is a Bus
Fare is high
This is a Four Wheeler
This is a Vehicle
MULTIPATH INHERITANCE
 A- Base class, B and C derived from A , Class D - derived form B & C
 D inherits all the features of B & C directly and inherits features of class A indirectly
through B & C
 Ambiguity occurs : because the main base class is inherited twice.
 To avoid ambiguity a keyword “virtual” is used.
31
Class A
Class D
Class B
Main Base class
Class C
Derived class
32
Class Vehicle
Class Four_Wheeler
Class Bus
Class Fare
Base classes
Derived classes
class Vehicle
{
public:
void show()
{
cout<< “This is a Vehicle";
}
};
class Four_Wheel: public Vehicle
{
public:
void display()
{
cout<< "This is a Four_Wheeler";
}
};
class Fare : public Vehicle
{
public:
void dip()
{
cout<< “Fare is high";
}
};
33
class Bus : public Four_wheel, Fare
{
public:
void print()
{
cout<< “This is a Bus";
}
};
Void main()
{
Bus obj;
obj.print();
obj.dip();
obj.display();
obj.show();
}
OUTPUT:
This is a Bus
Fare is high
This is a Four Wheeler
This is a Vehicle
VIRTUAL BASE CLASS
 In multipath inheritance child class could have duplicate sets of members
inherited from a single base class.
 Use : To avoid ambiguity due to multipath inheritance.
 When classes are declared virtual  complier takes essential caution to
avoid duplication.
 Keyword “virtual” is used with the base class when it is inherited.
34
e.g.
Class A1
{
protected:
int a1;
};
Class A2 : virtual public A1
{
protected:
int a2;
};
Class A3 : virtual public A1
{
protected:
int a3;
};
35
e.g.
Class A4 : public A2,A3
{
protected:
int a4;
};
 Here using object of A4, it can access
a1,a2,a3 and a4.
Class A1
Class A4
Class A3
Class A2
ABSTRACT CLASS
 when a class is not used for creating objects then it is called abstract class.
 Abstract class can act as base class only.
 It is used for inheriting and not used for object creation.
 An abstract class gives a skeleton or structure using which other classes are
created.
36
37
Class A
{
public:
int x ;
class B
{
public:
int y ;
};
};
Class C : public A, A :: B
{
public:
int z ;
void show ( )
{
cout<<“X=“<<x;
cout<<“Y=“<<y;
cout<<“Z=“<<z;
}
C ( int j, int k, int l)
{
x=j;
y=k;
z=l;
}
};
Void main ( )
{
C c (4,7,1);
c.show();
}
OUTPUT:
X = 4
Y = 7
Z = 1
ADVANTAGES
 Provides reusability
 The derived classes extend the properties of base class
 Generate more dominant objects.
 Same Base class can be used by number of derived class.
 All Derived class has same properties of base class.
38
DISADVANTAGES
 Inappropriate use of inheritance makes programs more
complex.
 Invoking member functions using objects create more
compiler overhead.
 In Class hierarchy various data elements remains unused.
 All Memory allocated is not utilized.
39

More Related Content

PPT
Inheritance
PPT
Inheritance
PPTX
Inheritance in c++ by Manan Pasricha
PPTX
Ritik (inheritance.cpp)
PPTX
Week 8 - OOP Inheritance11111111111.pptx
PPT
Inheritance
PDF
chapter-10-inheritance.pdf
PPTX
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
Inheritance
Inheritance
Inheritance in c++ by Manan Pasricha
Ritik (inheritance.cpp)
Week 8 - OOP Inheritance11111111111.pptx
Inheritance
chapter-10-inheritance.pdf
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx

Similar to MODULE2_INHERITANCE_SESSION1.ppt computer (20)

PPT
inheritence
PPT
11 Inheritance.ppt
PPT
Inheritance in C++
PDF
Inheritance
PDF
Inheritance
PDF
PPTX
OOP unit II inheritance.pptx object oriented programming
PPTX
Inheritance
PPTX
Inheritance in OOPS
PPTX
Inheritance and Interfaces
PDF
Inheritance chapter-6-computer-science-with-c++ opt
PPTX
Inheritance
PPTX
Multiple Inheritance
PPTX
Introduction to inheritance and different types of inheritance
PPTX
iheritence.pptx
PPSX
PPTX
Inheritance
PPT
Inheritance in C++
PPT
Inheritance.ppt
PPTX
Inheritance (with classifications)
inheritence
11 Inheritance.ppt
Inheritance in C++
Inheritance
Inheritance
OOP unit II inheritance.pptx object oriented programming
Inheritance
Inheritance in OOPS
Inheritance and Interfaces
Inheritance chapter-6-computer-science-with-c++ opt
Inheritance
Multiple Inheritance
Introduction to inheritance and different types of inheritance
iheritence.pptx
Inheritance
Inheritance in C++
Inheritance.ppt
Inheritance (with classifications)
Ad

Recently uploaded (20)

PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
UNIT 4 Total Quality Management .pptx
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
DOCX
573137875-Attendance-Management-System-original
PDF
Well-logging-methods_new................
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
Welding lecture in detail for understanding
PPT
Project quality management in manufacturing
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
Sustainable Sites - Green Building Construction
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
UNIT 4 Total Quality Management .pptx
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Model Code of Practice - Construction Work - 21102022 .pdf
573137875-Attendance-Management-System-original
Well-logging-methods_new................
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Welding lecture in detail for understanding
Project quality management in manufacturing
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Foundation to blockchain - A guide to Blockchain Tech
bas. eng. economics group 4 presentation 1.pptx
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Sustainable Sites - Green Building Construction
CH1 Production IntroductoryConcepts.pptx
Operating System & Kernel Study Guide-1 - converted.pdf
Ad

MODULE2_INHERITANCE_SESSION1.ppt computer

  • 2. CONTENTS  Introduction  Access specifiers and inheritance  Types of inheritance  Virtual base class  Abstract classes  Advantages & disadvantages - inheritance 2
  • 3. 3 Grand Parents PARENT 1 PARENT 2 CHILD 11 CHILD 12 CHILD 21 CHILD 22 PARENT – CHILD RELATIONSHIP
  • 4. INTRODUCTION  INHERITANCE - An essential characteristics of object oriented programming.  Existing classes are main components.  New classes are created from existing class.  i.e. properties of existing class are extended to new class.  Existing classes are called BASE CLASS.  Newley created classes are called DERIVED CLASS.  Definition : The procedure of creating a new class from one or more existing classes is termed as inheritance.  Relationship between base and derived class is known as KIND OF RELATIONSHIP.  Accessibility : Object of derived class can access members of base class as well as derived class, but object of base class cannot access members of derived classes. 4
  • 5. 5 MEMBER A MEMBER B MEMBER A MEMBER B MEMBER C MEMBER D BASE CLASS DERIVED CLASS
  • 6.  REUSABILITY :It means the reuse of properties of base class in the derived class.  Reusability is achieved using inheritance.  Base class is also called as : super class, parent class or ancestor class  Derived class is also called as sub class, child class or descendent class.  A class can be derived for more than one class and also it is possible to derive a class from previously derived class. 6
  • 7. 7 MEMBER A MEMBER B MEMBER A MEMBER B MEMBER B MEMBER C BASE CLASS DERIVED CLASS DERIVED CLASS MEMBER A MEMBER C MEMBER D
  • 8. ACCESS SPECIFIERS AND INHERITANCE  Access specifiers : public, private and protected.  Public: object can access the public members of the class  Private: object cannot access the private members of the class  Protected: only object of derived class can access the protected members of the base class Syntax : class_name of derived class : access specifier name of base_class { ………… …………. …………. }; 8
  • 9. e.g. (1) Class B : public A { //members of class B }; Here class A – base class, class B --- derived class which is derived publicly.  Object of class B can access all the public members of class A. (2) Class B : private A //private derivation { //members of class B }; Here class A – base class, class B --- derived class which is derived privately. (3) Class B : A //by default private derivation { //members of class B }; Here class A – base class, class B --- derived class which is derived privately. (4) Class B : protected A //protected derivation { //members of class B }; Here class A – base class, class B --- derived class which is derived protected. 9
  • 10.  When class is derived publicly, then all the public members of the base class can be accessed directly in the derived class and it cannot access the private members of the base class. 10 PUBLIC INHERITANCE Public members Private members OBJECT Base class Derived class
  • 11. PUBLIC INHERITANCE e.g. Class A { public: int x; }; Class B : public A //derived class { public : int y; }; Void main() { B b; b.x = 20; b.y = 30; cout<<“n Member of A : “<<b.x; cout<<“n Member of B : “<<b.y; } Output : Member of A :20 Member of B :30 11
  • 12.  Object of privately derived class cannot directly access the public members of base class  Thus member functions are used to access members 12 PRIVATE INHERITANCE Public members OBJECT Base class Derived class Public members functions Private members
  • 13. PRIVATE INHERITANCE e.g. Class A { public: int x; }; Class B : private A //derived class { public : int y; B( ) //constructor { x = 20; y = 40; } void show( ) { cout<<“n X= “<<x; cout<< “n Y= “<<y; } }; Void main() { B b; //object creation b . show( ); } Output : X =20 Y=40 13
  • 14.  Object of privately derived class cannot directly access the public members of base class  Thus member functions are used to access members 14 PROTECTED INHERITANCE Public members OBJECT Base class Derived class Public members functions Private members
  • 15. PROTECTED INHERITANCE e.g. Class A { public: int x; }; Class B : private A //derived class { public : int y; B( ) //constructor { x = 20; y = 40; } void show( ) { cout<<“n X= “<<x; cout<< “n Y= “<<y; } }; Void main() { B b; //object creation b . show( ); } Output : X =20 Y=40 15
  • 16. TYPES OF INHERITANCE 1) Single Inheritance 2) Multiple Inheritance 3) Hierarchical Inheritance 4) Multilevel Inheritance 5) Hybrid Inheritance 6) Multipath Inheritance 16
  • 17. SINGLE INHERITANCE  Only one class is derived from a single class  Further the derived class is not used as a base class.  Newley created class receives entire characteristics of base class. 17 Class ABC Base class Class abc Derived class
  • 18. class Vehicle //base class { public: void show() { cout<< "This is a Vehicle"; } }; class Car : public Vehicle //derived { public: void print() { cout<< "This is a Car"; } }; 18 Void main() { Car obj; obj.show(); obj.print(); } OUTPUT: This is a Vehicle This is a Car Class Vehicle Class Car
  • 19. MULTIPLE INHERITANCE  A class is derived from more than one base classes 19 Class A Class E Derived class Class B Class C
  • 20. 20 Class Vehicle Class Car Derived class Class Four_wheeler Base classes
  • 21. class Vehicle //base { public: void show() { cout<< "This is a Vehicle"; } }; class Four_Wheeler //base { public: void display() { cout<< "This is a Four wheeler"; } }; 21 class Car : public Vehicle, Four_wheeler { public: void print() { cout<< "This is a Car"; } }; Void main() { Car obj; obj.show(); obj.display(); obj.print(); } OUTPUT: This is a Vehicle This is a Four wheeler This is a Car
  • 22. HIERARCHICAL INHERITANCE  A- Base class, B,C & D derived  Further B,C & D are not used for deriving classes 22 Class A Class C Class B Class D
  • 23. 23 Class Vehicle Class Bus Derived class Class Car Base classes
  • 24. class Vehicle { public: void show() { cout<< "This is a Vehicle"; } }; class Car : public Vehicle { public: void display() { cout<< "This is a Car"; } }; 24 class Bus : public Vehicle { public: void print() { cout<< "This is a Bus"; } }; Void main() { Car obj1; Bus obj2; obj1.show(); obj1.display(); obj2.show(); obj2.print(); } OUTPUT: This is a Vehicle This is a Car This is a Vehicle This is a Bus
  • 25. MULTILEVEL INHERITANCE  A- Base class, B derived from A , C- derived form C  C inherits all the features of A & B. 25 Class A Class C Class B Base class1 Base class2
  • 26. 26 Class Vehicle Class Four_Wheeler Class Car Base class1 Base class2 Derived class
  • 27. class Vehicle { public: void show() { cout<< "This is a Vehicle"; } }; class Four_Wheel: public Vehicle { public: void display() { cout<< "This is a Car"; } }; 27 class Car : public Four_wheel { public: void print() { cout<< "This is a Bus"; } }; Void main() { Car obj1; Bus obj2; obj1.show(); obj1.display(); obj2.show(); obj2.print(); } OUTPUT: This is a Vehicle This is a Car This is a Vehicle This is a Bus
  • 28. HYBRID INHERITANCE  A- Base class, B derived from A , Class D - derived form B & C  D inherits all the features of B & C directly and inherits features of class A indirectly through B 28 Class A Class D Class B Base class Class C Derived class
  • 29. 29 Class Vehicle Class Four_Wheeler Class Bus Class Fare Base classes Derived classes
  • 30. class Vehicle { public: void show() { cout<< “This is a Vehicle"; } }; class Four_Wheel: public Vehicle { public: void display() { cout<< "This is a Four_Wheeler"; } }; class Fare { public: void dip() { cout<< “Fare is high"; } }; 30 class Bus : public Four_wheel, Fare { public: void print() { cout<< “This is a Bus"; } }; Void main() { Bus obj; obj.print(); obj.dip(); obj.display(); obj.show(); } OUTPUT: This is a Bus Fare is high This is a Four Wheeler This is a Vehicle
  • 31. MULTIPATH INHERITANCE  A- Base class, B and C derived from A , Class D - derived form B & C  D inherits all the features of B & C directly and inherits features of class A indirectly through B & C  Ambiguity occurs : because the main base class is inherited twice.  To avoid ambiguity a keyword “virtual” is used. 31 Class A Class D Class B Main Base class Class C Derived class
  • 32. 32 Class Vehicle Class Four_Wheeler Class Bus Class Fare Base classes Derived classes
  • 33. class Vehicle { public: void show() { cout<< “This is a Vehicle"; } }; class Four_Wheel: public Vehicle { public: void display() { cout<< "This is a Four_Wheeler"; } }; class Fare : public Vehicle { public: void dip() { cout<< “Fare is high"; } }; 33 class Bus : public Four_wheel, Fare { public: void print() { cout<< “This is a Bus"; } }; Void main() { Bus obj; obj.print(); obj.dip(); obj.display(); obj.show(); } OUTPUT: This is a Bus Fare is high This is a Four Wheeler This is a Vehicle
  • 34. VIRTUAL BASE CLASS  In multipath inheritance child class could have duplicate sets of members inherited from a single base class.  Use : To avoid ambiguity due to multipath inheritance.  When classes are declared virtual  complier takes essential caution to avoid duplication.  Keyword “virtual” is used with the base class when it is inherited. 34
  • 35. e.g. Class A1 { protected: int a1; }; Class A2 : virtual public A1 { protected: int a2; }; Class A3 : virtual public A1 { protected: int a3; }; 35 e.g. Class A4 : public A2,A3 { protected: int a4; };  Here using object of A4, it can access a1,a2,a3 and a4. Class A1 Class A4 Class A3 Class A2
  • 36. ABSTRACT CLASS  when a class is not used for creating objects then it is called abstract class.  Abstract class can act as base class only.  It is used for inheriting and not used for object creation.  An abstract class gives a skeleton or structure using which other classes are created. 36
  • 37. 37 Class A { public: int x ; class B { public: int y ; }; }; Class C : public A, A :: B { public: int z ; void show ( ) { cout<<“X=“<<x; cout<<“Y=“<<y; cout<<“Z=“<<z; } C ( int j, int k, int l) { x=j; y=k; z=l; } }; Void main ( ) { C c (4,7,1); c.show(); } OUTPUT: X = 4 Y = 7 Z = 1
  • 38. ADVANTAGES  Provides reusability  The derived classes extend the properties of base class  Generate more dominant objects.  Same Base class can be used by number of derived class.  All Derived class has same properties of base class. 38
  • 39. DISADVANTAGES  Inappropriate use of inheritance makes programs more complex.  Invoking member functions using objects create more compiler overhead.  In Class hierarchy various data elements remains unused.  All Memory allocated is not utilized. 39