![]() |
Equality in Java
PrerequisitesThis Magercise covers some points on the semantics of equality in Java.There are two ways to compare objects in Java, one is using the operator ==, which is true if the two objects being compared have the same identity (they are the same object). The other way is to use the equals method, which is defined in the class Object (and thus for all objects), and can be used to determine if two objects are equal on a value basis. Equality is discussed in detail in the course notes. Work LocationPerform all work for this magercise in VisualAge project MageLang Magercises, package magercises.Equality 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:
Add a similar method called findEmployeeNamed. This method takes as its argument a String name and tries to find an Employee of that name. It returns the Employee object if successful. Add code in the main method of the EqualityTest class to use these two new methods to search for some employees. Run your solution via the EqualityTest class.
|
Copyright © 1996-1997 MageLang Institute. All Rights Reserved. |