::: ''This task is about derived types; &nbsp; for implementation inheritance, see [[Polymorphism]].


Inheritance is an operation of [[type algebra]] that creates a new type from one or several parent types. 

The obtained type is called '''derived type'''. 

It inherits some of the properties of its parent types. 

Usually inherited properties are:
:::* &nbsp; methods
:::* &nbsp; components
:::* &nbsp; parts of the representation


The [[classes | class]] of the new type is a &nbsp; '''subclass''' &nbsp; of the classes rooted in the parent types. 

When all (in certain sense) properties of the parents are preserved by the derived type, &nbsp; it is said to be a [[wp:Liskov_substitution_principle|Liskov subtype]]. 

When properties are preserved then the derived type is ''substitutable'' for its parents in all contexts. &nbsp; Usually full substitutability is achievable only in some contexts.


Inheritance is
:::* &nbsp; '''single''', when only one parent is allowed
:::* &nbsp; '''[[multiple inheritance | multiple]]''', otherwise


Some single inheritance languages usually allow multiple inheritance for certain [[abstract type]]s, interfaces in particular.

Inheritance can be considered as a relation parent-child. 

Parent types are sometimes called '''supertype''', the derived ones are '''subtype'''. &nbsp; This relation is [[wp:Transitive_relation|transitive]] and [[wp:Reflexive_relation|reflexive]]. 

Types bound by the relation form a [[wp:Directed_acyclic_graph directed acyclic graph]] (ignoring reflexivity). 

With single inheritance it becomes a [[wp:Tree_(graph_theory)|tree]].


;Task:
Show a tree of types which inherit from each other. 
::: &nbsp; At the top of the tree should be a class called &nbsp; '''Animal'''. 
::: &nbsp; The second level should have '''Dog''' and '''Cat'''. 
::: &nbsp; Under &nbsp; '''Dog''' &nbsp; should be &nbsp; '''Lab''' &nbsp; and &nbsp; '''Collie'''. 
::: &nbsp; None of the classes need to have any functions, &nbsp; the only thing they need to do is inherit from the specified superclasses <br> &nbsp; (overriding functions should be shown in [[Polymorphism]]). 


The tree should look like this:
<pre>
                        Animal
                          /\
                         /  \
                        /    \
                      Dog    Cat
                      /\
                     /  \
                    /    \
                  Lab  Collie
</pre>
<br><br>

