Object-oriented programming (OOP), inheritance is a way to establish Is-a relationship between objects.[note 1] It is often confused as a way to reuse the existing code which is not a good practice because inheritance for implementation reuse leads to Tight Coupling. Re-usability of code is achieved through composition | Chapter 9 - Object-Oriented Programming: Inheritance Outline Introduction Base Classes and Derived Classes protected Members Relationship between Base Classes and Derived Classes Case Study: Three-Level Inheritance Hierarchy Constructors and Destructors in Derived Classes “Uses A” and “Knows A” Relationships public, protected and private Inheritance Software Engineering with Inheritance Introduction Inheritance Software reusability Create new class from existing class Absorb existing class’s data and behaviors Enhance with new capabilities Derived class inherits from base class Derived class More specialized group of objects Behaviors inherited from base class Can customize Additional behaviors Introduction Class hierarchy Direct base class Inherited explicitly (one level up hierarchy) Indirect base class Inherited two or more levels up hierarchy Single inheritance Inherits from one base class Multiple inheritance Inherits from . | Chapter 9 - Object-Oriented Programming: Inheritance Outline Introduction Base Classes and Derived Classes protected Members Relationship between Base Classes and Derived Classes Case Study: Three-Level Inheritance Hierarchy Constructors and Destructors in Derived Classes “Uses A” and “Knows A” Relationships public, protected and private Inheritance Software Engineering with Inheritance Introduction Inheritance Software reusability Create new class from existing class Absorb existing class’s data and behaviors Enhance with new capabilities Derived class inherits from base class Derived class More specialized group of objects Behaviors inherited from base class Can customize Additional behaviors Introduction Class hierarchy Direct base class Inherited explicitly (one level up hierarchy) Indirect base class Inherited two or more levels up hierarchy Single inheritance Inherits from one base class Multiple inheritance Inherits from multiple base classes Base classes possibly unrelated Chapter 22 Introduction Three types of inheritance public Every object of derived class also object of base class Base-class objects not objects of derived classes Example: All cars vehicles, but not all vehicles cars Can access non-private members of base class Derived class can effect change to private base-class members Through inherited non-private member functions private Alternative to composition Chapter 17 protected Rarely used Introduction Abstraction Focus on commonalities among objects in system “is-a” vs. “has-a” “is-a” Inheritance Derived class object treated as base class object Example: Car is a vehicle Vehicle properties/behaviors also car properties/behaviors “has-a” Composition Object contains one or more objects of other classes as members Example: Car has a steering wheel Base Classes and Derived Classes Base classes and derived classes Object of one class “is an” object of another class .