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

Inheritance Types in C#: Examples Explained

Multiple Inheritance allows a class to inherit from multiple base classes, leading to potential ambiguity and complexity, while Hierarchical Inheritance involves multiple derived classes inheriting from a single base class, which is simpler and avoids ambiguity. The structure of Multiple Inheritance is many-to-one, whereas Hierarchical Inheritance is one-to-many. Both inheritance types serve different purposes in code reusability and design.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Inheritance Types in C#: Examples Explained

Multiple Inheritance allows a class to inherit from multiple base classes, leading to potential ambiguity and complexity, while Hierarchical Inheritance involves multiple derived classes inheriting from a single base class, which is simpler and avoids ambiguity. The structure of Multiple Inheritance is many-to-one, whereas Hierarchical Inheritance is one-to-many. Both inheritance types serve different purposes in code reusability and design.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Difference between Multiple Inheritance and

Hierarchical Inheritance

Definition
• Multiple Inheritance: A class can inherit properties and methods from two or more base classes.
• Hierarchical Inheritance: Multiple classes inherit from a single base class.

Aspect Multiple Inheritance Hierarchical Inheritance


Definition One derived class inherits from multiple baseMultiple
[Link] classes inherit from a single base class.
Structure Many → One One → Many
Code Reusability Combines features from multiple classes. Shares base class features with many classes.
May
Ambiguity
lead to diamond problem if the same base class is inherited
No ambiguity,
more thansince
once.
only one base class is common.
Complexity More complex to implement and maintain. Simpler and easier to understand.
Example class C : public A, public B class B : public A; class C : public A

Conclusion
• Multiple Inheritance is useful when a class needs features of multiple classes, but it may cause
ambiguity issues. • Hierarchical Inheritance is useful when multiple classes need to share the same
base functionality.

You might also like