Modeling the IS-A relationship

If a class is a sub-type of another, code that operates on the superclass should operate similarly on its subtypes. This models the IS-A relationship.

Consider a ColouredCircle, which allows a circle to contain a colour. It is a type of circle, so anything that a circle can do, it must be able to do.

Inheritance needs to preserve the meaning of subtyping.

Run-Time Type

In Java, a variable of type can hold a value of type if .

Thus, given the following:

T var = new S();

The compile-time type of var is , but the run-time type is .