Working With Class Information


Prerequisites

In Java, a considerable amount of information about classes can be obtained at runtime, this sort of information is often referred to as meta information. In particular, given an Object, it is always possible to figure out what Class it belongs to. In this Magercise, the methods Object.getClass and Class.getName will be used in the Company class to tally the total value of all contracts held with individuals.

More information on these, and other useful meta-related methods, can be seen by looking at the JDK reference for Object and Class. Note that some of the methods can throw exceptions. One of the exception Magercises shows how to safely use them.

More information on class methods is covered in the course notes.

Work Location

Perform all work for this magercise in VisualAge project MageLang Magercises, package magercises.meta.

If this project does not appear in your Workspace add it from the repository (if it exists there) or create a new project using this name.

Tasks

Perform the following tasks:

  1. Implement the totalIndividualContracts method of the Company class. The signature of this method is given in the starter file.

The task numbers above are linked to the step-by-step help page. Also available is a complete solution to the problem, and expected behavior, to demonstrate it.

Copyright © 1996-1997 MageLang Institute. All Rights Reserved.