Let's say we are building a financial application that keeps track of a user's wealth, which may include various types of asset. The following diagram shows a hierarchy of abstract types and their parent–child relationship. In this design, an Asset may be a Property, an Investment, or just Cash types. A Property can be a House or an Apartment. An Investment could be FixedIncome or Equity. As a convention, in order to indicate that they are abstract types rather than concrete types, we have chosen to italicize their names in the boxes:
To create an abstract type hierarchy, we can use the following code:
abstract type Asset end
abstract type Property <: Asset end
abstract type Investment <: Asset end
abstract type Cash <: Asset end
abstract type House <: Property end
abstract type Apartment <: Property end
abstract type FixedIncome <: Investment end
abstract type Equity <: Investment end
The <: symbol represents an is-a-subtype-of relationship. So, the Property type is a subtype of Asset, the Equity type is a subtype of Investment, and so on.
While the Asset abstract type seems to be at the top level of the hierarchy in reality, it also has a supertype called Any, which is implicit when no supertype is specified and an abstract type is defined. The Any code phrase is the top-level supertype in Julia.