Exercise 2

1 Using the Extends Clause in Redeclarations

The next exercise will test if you know how to use an extends clause when redeclaring.

First write a class
A with a Real parameter salt.

We also need a class
Asub , extending A and having two Real parameters: pepper and basil. The parameter salt shall be set to 20.

Then we need a class
AInst, containing a variable a, which is an instance of A, in which you should set salt to 100.

Write a class
AIred, extending AInst. Also, change the type of the component a to AIsub and set the pepper parameter to 200.

Write a similar class
AIred2 that instead of extending AInst, declares a component of type AInst. As above, the type of component a should be changed to AIsub.


1.1.1 Class A

1.1.2 Class Asub

1.1.3 Class AInst

1.1.4 Class AIred

1.1.5 Class AIred2

1.1.6 Simulation of AIred