A game may have archers, pikemen, and knights that are all warriors. In Julia, a type hierarchy expresses that relationship through an abstract parent type and concrete child types. Unlike class hierarchies in many object-oriented languages, Julia’s hierarchies also include numbers, strings, and collections. section 7.3.1 section 7.2
Follow a number’s ancestry
Start with `typeof(42)`, which returns `Int64`. Repeatedly calling `supertype` follows `Int64 → Signed → Integer → Real → Number → Any`. `Any` is the top: `supertype(Any)` returns `Any`. Travel downward with `subtypes(Number)` to find `Complex` and `Real`, then inspect their children. Use `Int8 <: Integer` to ask whether one type is a subtype of another; it returns `true`. section 7.2
The distinction between abstract and concrete matters when creating values. `Warrior` can group related types, but `Warrior()` cannot create an object; a concrete `Archer` can. Only leaf nodes of a Julia type hierarchy can be concrete, and a concrete type cannot be subtyped. section 7.3.1 section 7.5
Listing 7.5 Definition of types in battle simulator
abstract type Warrior end #1
mutable struct Archer <: Warrior #2
name::String
health::Int
arrows::Int
end
mutable struct Pikeman <: Warrior
name::String
health::Int
end
mutable struct Knight <: Warrior
name::String
health::Int
mounted::Bool #3
end
This battle-simulator definition places three concrete `mutable struct` types beneath `abstract type Warrior`. Each declares its own fields: an abstract type cannot contain fields, so shared `name` and `health` fields are a convention here, not an enforced inheritance rule. The `<:` syntax declares the parent relationship. section 7.3.1
The hierarchy has practical consequences. An `Any`-typed array accepts a string alongside integers, while assigning a string to an `Integer`-typed array fails. Types also help select methods: Julia’s multiple dispatch considers the types of all arguments, rather than only the first. section 7.2 section 7.5



