Type Hierarchy
Classes allow us to define our own data types. Indeed, Student
and GradStudent
are data types. More specifically, GradStudent
is a subtype of Student
. And by the same token, Student
is the base type of GradStudent
Since inheritance is transitive, it allows us to create a hierarchy of types. This makes object-oriented programming a particularly useful paradigm for modeling real-world problems because the entities in those problems often naturally exhibit such a hierarchy.
Example: Fruits
Example: Animals
Exercise We are building a software solution for a banking system. We have the following classes so far: Account
, Checking
, Saving
, Debit
, Credit
. Arrange these classes into the following type hierarchy.