Inheritance, Exercises

A

Exercises 6.1 and 6.2 in the book. The topic is inheritance and constructors.

B

Exercise 6.15 in the book. The topic is packages and protected.

Extra Assignments

E1

A part can be either simple or composite (consists of parts that consists of parts and so on, i.e., a tree structure). Each part has a price, as an example a simple part has the price listed for the part, whereas the price for a composite part is the sum of all the parts that make up the composite part. Use the composite design pattern to implement a method price on both simple and composite parts.

E1

Build a two version of a simple class with a method calc that does a small computation, e.g., adding two integers and returning the result. For the first version of class the calc method should be final for the other version it should not be final. Measure if the use of final has a positive effect on the execution speed.