User Tools

Site Tools


3._create_a_spatializedtree_class

The Java training online

Back to the table of contents

3. Create a SpatializedTree class

Purpose: Explore the class inheritance relationship

Statement of the exercise:

  1. Create a new class in the same package, named SpatializedTree. This class adds two instance variables called x and y, the position of the tree. Write a constructor taking 3 parameters: dbh, x and y. Add a setter for x and y, and a getter for each of them. Propose a toString () method to display dbh, x and y.
  2. Add code in the main method of exercise 1. to create a SpatializedTree with dbh 5.6cm and location (2, 1), and print its toString() method to the terminal

Helper and solution

Back to the table of contents

3._create_a_spatializedtree_class.txt ยท Last modified: 2021/12/13 09:28 by 127.0.0.1