Table of Contents

Lesson 4

Classes and objects relations.

Objectives

Documentation

Pachete java
Specificatori de acces
Reutilizarea claselor
Thinking in Java : Chapter 6 - Reusing classes

Exercises

Considering the exercises bellow. Follow the instructions and implement the programs. For each program create an appropriate test class for testing each program.

Exercise 1

A class called circle is designed as shown in the following class diagram. It contains:

Exercise 2

A class called Author is designed as shown in the class diagram. It contains:

Exercise 3

A class called Book is designed as shown in the class diagram. It contains:

Exercise 4

Modify the Book class from previous exercise to support one or more authors by changing the instance variable authors to an Author array. Reuse the Author class written earlier.

Notes:

Exercise 5

In this exercise, a subclass called Cylinder is derived from the superclass Circle as shown in the class diagram.

Notes:

Exercise 6

Write a superclass called Shape (as shown in the class diagram), which contains:

The Circle class contains:

The Rectangle class contains:

Write a class called Square, as a subclass of Rectangle. Square has no instance variable, but inherits the instance variables width and length from its superclass Rectangle.