Lecture 8-Week8_Multilevel Inheritance, Multiple Inheritance
Lecture 8-Week8_Multilevel Inheritance, Multiple Inheritance
Programming
(CS1143)
Week 8
Multi-level Inheritance
Multiple Inheritance
2
Class Hierarchies
So far we have only seen one derived class inheriting from one base
class. However all of the following cases are possible.
1. Multiple classes can be derived from the same base class.
2. A base class can also derive from another base class (Multi-level
inheritance)
3. A derived class can derive from multiple base classes (Multiple Inheritance)
3
Multiple Classes Deriving from the
Same Base Class
4
Multi-level Inheritance
5
Multiple Inheritance
6
Outline
Multi-level Inheritance
Multiple Inheritance
7
Multiple Inheritance
8
9
10
Description
11
Description Continued
12
Program Discussion (W8-P2-
S23.cpp)
13
Outline
Multi-level Inheritance
Multiple Inheritance
14
Multiple Inheritance
15
Program Discussion (W8-P3-
S23.cpp)
16
Multiple Inheritance-Diamond
Problem
Suppose we have a class Person that defines one single data member,
name.
Both Student and Professor classes inherit from Person class.
This data member is inherited in both the Student object and the
Professor object.
Since the TA (teaching assistant) class inherits the Student and
Professor classes, the data member name is duplicated in the TA
class.
We cannot use inheritance in this case without removing the
duplicate data member.
17
18
Program Discussion (W8-P4-
S23.cpp)
19
Solution
20
This is all for Week 8
21