
- OOAD Tutorial
- OOAD - Home
- OOAD - Object Oriented Paradigm
- OOAD - Object Oriented Model
- OOAD - Object Oriented System
- OOAD - Object Oriented Principles
- OOAD - Object Oriented Analysis
- OOAD - Dynamic Modelling
- OOAD - Functional Modelling
- OOAD - UML Analysis Model
- OOAD - UML Basic Notations
- OOAD - UML Structural Diagrams
- OOAD - UML Behavioural Diagrams
- OOAD - Object Oriented Design
- OOAD - Implementation Strategies
- OOAD - Testing & Quality Assurance
- OOAD Useful Resources
- OOAD - Quick Guide
- OOAD - Useful Resources
OOAD Princhiples Q/A #1
Question:What is inheritance? Discuss types of inheritance with example.
Answer:
Inheritance
Inheritance is the mechanism to allow a class A to inherit properties of class b i.e A inherits from B. Objects of class A thus have accesses to attribute and methods of class B without the need to redefine them. If class A inherits from class B , then B is called super class of A and A is called subclass of B. Supper classes are also called base classes or parents classes. Subclasses may be called derived classes or child classes.

Importance of inheritance
Inheritance is one of the most powerful features of object oriented programming. Most important advantages of inheritance are:
Reusability - Inheritance allows deriving new classes from existing classes without modifying it. This helps in reusability of information in the child class as well as adding extra functionality in to it.
Saves times and efforts - The concept of reusability achieved by inheritance saves a lot of programmer time and effort as the main code written can be reused in various situations as needed.
Closeness with the real world - Inheritance allows the capability to express the inheritance relationship and ensures closeness with the real world models.
Easy modification - Inheritance allows modification to be done in an easier manner.
Transitive Nature of inheritance - If a class A inherits properties of another class B then all subclasses of A will automatically inherits the properties of B. This concept is called transitive nature of inheritance.
Syntax of defining a sub class from super class
class subclass: visibility_mode superclass_name { ... }
Here class is keyword. superclass_name is the neme of the derived class which is a valid identifier. Visibility modes are of three types public, private and protected.
Types of Inheritance
Various types of inheritance are supported by C++. These are:
Single Inheritance - When a subclass inherits properties from one base class, it is called single inheritance. In single inheritance , there is only one base class and one derived class.
Multiple Inheritance - When a subclass inherits properties from multiple base classes, it is known as multiple inheritance. In multiple Inheritance , there is only one derived class and several base classes.
Hierarchical Inheritance - When two or more subclasses inherit properties from a single base class, It is known as Hierarchical inheritance . In hierarchical inheritance , the feature of one class may be inherited by more then one class.
Multilevel Inheritance - In multilevel Inheritance , A class is derived from an already derived class. The transitive nature of inheritance is reflected by this form of inheritance.
Hybrid Inheritance - When two or more type of inheritance are required to code a program, such type of inheritance is called hybrid inheritance. Figure shown below is a combination of multilevel and multiple inheritance.