0% found this document useful (0 votes)
2 views1 page

Structured Programming

Uploaded by

mugerwasamuel8
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Structured Programming

Uploaded by

mugerwasamuel8
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

[Type here]

Question 2.
Types of Inheritance in Object-Oriented Programming

Inheritance is one of the key concepts in Object-Oriented Programming (OOP) in C++. It


allows a class to acquire properties and behaviours from another class. This helps in code
reusability and makes programs easier to maintain and extend. In C++, there are different
types of inheritance depending on how classes are related to each other.

[Link] Inheritance

Single inheritance is when one class inherits from only one base class. In this case, there is a
single parent and a single child class. For example, a class called Animal can be the base
class, and another class called Dog can inherit from it. This means the Dog class can use the
features of the Animal class.

[Link] Inheritance

Multiple inheritance occurs when one class inherits from more than one base class. This
means a child class can have more than one parent class. For example, a class Student can
inherit from both Teacher and Player classes. This allows the student class to use features
from both parent classes.

[Link] Inheritance

Multilevel inheritance is when a class is derived from another derived class. In this case,
there is a chain of inheritance. For example, a class Animal can be the base class, Mammal
can inherit from Animal, and Dog can inherit from Mammal. This forms a parent-child-
grandchild relationship.

[Link] Inheritance

Hierarchical inheritance happens when multiple classes inherit from a single base class. For
example, classes like Dog and Cat can both inherit from the same base class Animal. This
means they share common features from the Animal class but can also have their own
specific behaviours.

[Link] Inheritance

Hybrid inheritance is a combination of two or more types of inheritance. It is used when a


program uses more than one inheritance structure at the same time. For example, a class
can be formed using both multiple and multilevel inheritance. However, it may lead to
complexity such as the diamond problem, which can be solved using virtual inheritance in C+
+.

[Type here]

You might also like