![]() |
Reference Semantics in Java
PrerequisitesThis Magercise demonstrates the semantics of assignment and reference in Java by building a one-to-one relationship between two objects.The starter classes Employee and Project have already been created for you in the VisualAge Workspace and are present in the Reference Semantics in Java project. Additionally, they already have the necessary pointers needed to refer to each other. What needs to be filled in is the setProject method of Employee, which sets up the relationship. In addition, this method must maintain referential integrity. This means that a Project cannot be in relation to an Employee unless that Employee is in relation to it, and vice versa. Here it is legal for the relationship to be null valued. The semantics of Java are discussed in detail in the course notes. Work LocationPerform all work for this magercise in VisualAge project MageLang Magercises, package magercises.Reference Semantics in Java. 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:
Augment the toString method of Employee to also print out the name of the current Project. This is a good place to use the ternary conditional operator ?: . Augment the toString method of Project to print out its current owner. Run the program via the RefTest class, and note the output that appears in the Console window.
|
Copyright © 1996-1997 MageLang Institute. All Rights Reserved. |