#
Inheritance

Sometimes there is a need to extend the behavior and properties of an existing class. The original class, known as the superclass, is extended to create a more specialized version of that class, known as the subclass. Inheritance of a class is achieved by using the keyword extends. The behavior and properties of the original class (field declarations, equations etc.) is reused and inherited by the subclass.

##
1
Inheritance of Equations

##
2
ColorData

##
3
ErrorColor and CorrectColor

This is an example of extending a simple Modelica class, ColorData.

##
4
Simulation of Color, CorrectColor and ErrorColor

Simulation of ErrorColor gives error since we try to declare a new variable red, of the type Integer, although it alredy exists with the type Real.

##
5
Color2

If two identical equations are locally declared in a subclass, then one of the equations are discarded. The class Color2 is identical to the class Color, since the equation defined in Color2 is identical to the one inherited from class Color, and only one of these equations are kept.

##
6
Color3

Equations that are mathematically equivalent, but not syntactically equivalent are not discarded. Since this is the case in class Color3, both equations are kept. This leads to an overdetermined system of equation.

##
7
Simulation of Color3

When simulating the class Color3 we get too many equations.