05: Equality, Namespaces, Packages, and the CLASSPATH

Submit this homework using Gradescope. You can type up your answers, or write legibly and scan them. Do not attempt to submit a paper copy in class, as it will not be accepted.


A. (3 points) Given the following code, what is the output? Assume a public number instance variable, and an equals() method within the Bus class that uses only this instance variable to check if two Bus objects values’ are semantically equal.

Bus busA = new Bus();
Bus busB = new Bus();

busA.number = 33; // The 33 is the Florida of PVTA bus routes.
busB.number = 33;

System.out.println(busA == busB);
System.out.println(busA.equals(busB));

Bus busC = busA;
busA = busB;

busA.number = 43;

System.out.println(busA == busC);
System.out.println(busA.equals(busC));

busC=busA;

System.out.println(busB == busC);
System.out.println(busB.equals(busC));

B. (1 point) Suppose you have a single directory on your CLASSPATH, /Users/student/src/. That is, the src directory (located inside student, which is in turn located inside Users directory) is on your classpath.

Suppose the first line of a Java source file named “Bear.java” is:

package animals.mammals;

Where exactly should this file be located? Specify the full path to the file. For example, a wrong answer is “in /Users/Bear.java”. Another wrong answer is /animals/mammals/Bear.java.

C. (2 points) Suppose we add a file named Eagle.java to the project above, and we want the Eagle class to reside in the animals.birds package. What should the first line (the package declaration) of the Eagle.java file be? And, what should the full path to the file be?

D. (1 point) Finally, suppose we want to reference the Eagle class from within the Bear.java source. What import statement must we to add to the Bear.java file? If none is necessary, say so.