0% found this document useful (0 votes)
2 views2 pages

Inheritance Types

The document outlines five types of inheritance in C++: Single, Multiple, Multilevel, Hierarchical, and Hybrid (Virtual) Inheritance. Each type is defined with syntax examples and accompanying diagrams to illustrate the relationships between classes. The Hybrid Inheritance section highlights the use of the virtual keyword to prevent ambiguity in class hierarchies.

Uploaded by

aunik3012
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 views2 pages

Inheritance Types

The document outlines five types of inheritance in C++: Single, Multiple, Multilevel, Hierarchical, and Hybrid (Virtual) Inheritance. Each type is defined with syntax examples and accompanying diagrams to illustrate the relationships between classes. The Hybrid Inheritance section highlights the use of the virtual keyword to prevent ambiguity in class hierarchies.

Uploaded by

aunik3012
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

1.

Single Inheritance

A derived class inherits from one base class.

Syntax (C++):
class A {
public:
void show();
};

class B : public A {
};

Diagram:
A
|
B

2. Multiple Inheritance

A derived class inherits from more than one base class.

Syntax (C++):
class A { };
class B { };

class C : public A, public B {


};

Diagram:
A B
\ /
C

3. Multilevel Inheritance

A class is derived from another derived class.

Syntax (C++):
class A { };
class B : public A { };
class C : public B { };

Diagram:
A
|
B
|
C

4. Hierarchical Inheritance
Multiple derived classes inherit from one base class.

Syntax (C++):
class A { };
class B : public A { };
class C : public A { };

Diagram:
A
/ \
B C

5. Hybrid (Virtual) Inheritance

Combination of multiple inheritance types. Virtual keyword avoids ambiguity.

Syntax (C++):
class A { };
class B : virtual public A { };
class C : virtual public A { };
class D : public B, public C { };

Diagram:
A
/ \
B C
\ /
D

You might also like