Inheritance in C++ Programming

Inheritance in C++ Programming
Slide Note
Embed
Share

Inheritance in C++ is a fundamental technique of Object-Oriented Programming, enabling classes to inherit properties from other classes. It simplifies application development, promotes code reuse, and speeds up implementation. Learn about base classes, derived classes, access specifiers, and modes of inheritance in C++.

  • C++
  • Inheritance
  • OOP
  • Programming
  • Classes

Uploaded on Apr 17, 2025 | 3 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Inheritance in C++

  2. What is Inheritance? Inheritance is a technique of OOPs where a class inherits some or all properties of another class. Allows us to define a class in terms of another class. Makes it easier to create and maintain an application. Provides an opportunity to reuse the code functionality and fast implementation time.

  3. Base Class: whose properties are inherited derived class: inherit the features of base class Syntax for inheritance: class derived-class : access-specifier base- class Access specifier may be public, private or protected. Colon indicates that the derived class name is derived from base class name.

  4. Access specifiers used in C++ Public: Public members of a class are accessed by member functions of its class itself and member functions of its derived classes. Private: Private members of a class are accessed only by the member functions of its class in which these are declared. other class members can not access private members of a class. Protected: Protected members are accessed by member functions within its class and any class immediately derived from it. It cannot be accessed by the functions out side these two classes.

  5. Modes of Inheritance Modes of Inheritance Private Public Protected

  6. Modes of Inheritance Private Mode: When a base class is privately inherited by the derived class, then Public and protected members of the base class become private members of the derived class and therefore they can be accessed only by member functions of derived class. They are inaccessible to the objects of the derived class Private members of the base class are not inherited.

  7. Public Mode: When a base class is publically inherited, then Public members of the base class become public members of thederived class. Protected members of base class become protected members of derived class. Therefore they are accessible to the objects of the derived class. Private members are not inherited.

  8. Protected Mode: When a base class is inherited in protected mode, then Public and protected members of base class become protected members in the derived class too and therefore they are accessible by the members functions of derived class. A private member is not inherited.

  9. Types of Inheritance It is of 5 types Single level inheritance Multilevel Inheritance Multiple Inheritance Hierarchical Inheritance Hybrid Inheritance

  10. Single level Inheritance In this type of inheritance one derived class inherits from only one base class. It is the most simplest form of Inheritance.

  11. Multilevel Inheritance In this type of inheritance the derived class inherits from a class, which in turn inherits from some other class. The Super class for one, is sub class for the other.

  12. Multiple inheritance In this type of inheritance a single derived class may inherit from two or more than two base classes.

  13. Hierarchical Inheritance In this type one class is inherited by multiple classes.

  14. Hybrid Inheritance It is a mixture of 2 or more of above types of inheritance. There is no pattern of deriving from classes.

More Related Content