Cse Lab4
Cse Lab4
Cse Lab4
Experiment Name: Introduction to Inheritance and its classification with Implement Code.
Objectives:
1. Improve software development efficiency by leveraging inheritance to reduce development
time through code reuse and abstraction.
5. Reduce redundancy in code by utilizing inheritance to establish common parent classes and
inherit shared functionality, leading to consistent results and minimizing storage costs
associated with redundant code.
Introduction: The capability of a class to derive properties and characteristics from another
class is called Inheritance.
Sub Class:
The class that inherits properties from another class is called Sub class or Derived Class.
Super Class:
The class whose properties are inherited by sub class is called Base Class or Super class.
Based on Implementation C++ supports five types of Inheritance:
1. Single Inheritance.
2. Multiple Inheritance.
3. Multilevel Inheritance.
4. Hierarchical Inheritance.
5. Hybrid Inheritance.
Single Inheritance: In single inheritance, a class is allowed to inherit from only one class.
i.e. one sub class is inherited by one base class only.
Class C Derived
cass
Multilevel Inheritance: In Multilevel inheritance, a class inherits its properties from another
derived class.
Single Inheritance:
Output:
Multiple Inheritance:
Output:
Multilevel Inheritance:
Output:
Conclusion:
In this lab, I delved into the concept of inheritance in C++. We explored its different forms,
such as single, multiple, and hierarchical inheritance, and learned how to implement them
effectively. By creating base and derived classes, we harnessed inheritance's power to
promote code reuse and maintainability.
Throughout the exercises, I identified the benefits of inheritance, including improved code
organization and flexibility. I also encountered challenges like the "diamond problem" in
multiple inheritance scenarios. Nonetheless, by mastering inheritance, I gained a valuable
tool for designing modular and scalable C++ code.