1 / 19

INHERITANCE

Learn about the concept of inheritance in programming, including its types, syntax, visibility, and usage in different programs. Explore the benefits and the various types of inheritance.

cmansour
Download Presentation

INHERITANCE

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. INHERITANCE Introduction Types Syntax Visibility Modes Example Programs

  2. What Is Inheritance? • Provides a way to create a new class from an existing class • The new class is a specialized version of the existing class • Ex: • ANIMAL • DOG • Poodle The relationship is “is-a” DOG is a ANIMAL with additional features

  3. The "is a" Relationship • Inheritance establishes an "is a" relationship between classes. • Student { id,name,dept,avg } • CSE_Student {rank} • Placement ( placed } • Terminologies • Base Class – Inherited • Derived Class – Inherits from base class • An object of a derived class 'is a(n)' object of the base class • A derived object has all of the characteristics of the base class

  4. TYPES • In C++, we have 5 different types of Inheritance. Namely, • Single Inheritance • Multiple Inheritance • Hierarchical Inheritance • Multilevel Inheritance • Hybrid Inheritance

  5. Merits • Reusability • Application Development Time is Less • Application Execution time is Less • Less Memory • Redundancy of the code is reduced

  6. Types of Inheritance 1. Single class Inheritance: Single inheritance is the one where you have a single base class and a single derived class. It is a Base class (super) Class Employee Class Manager it is a sub class (derived)

  7. Types of Inheritance 2. Multilevel Inheritance: In Multi level inheritance, a class inherits its properties from another derived class. it is a Base class (super) of B Class A it is a sub class (derived) of A and base class of class C Class B Class C derived class(sub) of class B

  8. Types of Inheritance 3. Multiple Inheritances: In Multiple inheritances, a derived class inherits from multiple base classes. It has properties of both the base classes. Base class Class A Class B Class C Derived class

  9. Types of Inheritance 4. Hierarchical Inheritance: In hierarchical Inheritance, it's like an inverted tree. So multiple classes inherit from a single base class. It's quite analogous to the File system in a unix based system. Class A Class C Class D Class B

  10. Types of Inheritance • 5. Hybrid Inheritance: • In this type of inheritance, we can have mixture of number of inheritances but this can generate an error of using same name function from no of classes, which will bother the compiler to how to use the functions. • Therefore, it will generate errors in the program. This has known as ambiguity or duplicity. • Ambiguity problem can be solved by using virtual base classes

  11. Types of Inheritance 5. Hybrid Inheritance: Class A Class B Class C Class D

More Related