Analyze the following code.
```
// Program 1:
public class Test {
public static void main(String[] args) {
Object a1 = new A();
Object a2 = new A();
System.out.println(a1.equals(a2));
}
}
class A {
int x;
public boolean equals(Object a) {
return this.x == ((A)a).x;
}
}
// Program 2:
public class Test {
public static void main(String[] args) {
Object a1 = new A();
Object a2 = new A();
System.out.println(a1.equals(a2));
}
}
class A {
int x;
public boolean equals(A a) {
return this.x == a.x;
}
}
```
a. Program 1 displays true and Program 2 displays true
b. Program 1 displays false and Program 2 displays true
c. Program 1 displays true and Program 2 displays false
d. Program 1 displays false and Program 2 displays false
c. Program 1 displays true and Program 2 displays false
In Program 1, the equals method in the Object class is overridden. a1.equals(a2) invokes this method. It returns true. In Program 2, the equals method in the Object class is not overridden. a1.equals(a2) invokes the equals method defined in the Object class, which returns false in this case.
You might also like to view...
Consider the array:
s( 0 ) = 7 s( 1 ) = 0 s( 2 ) = -12 s( 3 ) = 9 s( 4 ) = 10 s( 5 ) = 3 s( 6 ) = 6 The value of s( s( 6 ) – s( 5 ) ) is: a) 0 b) 3 c) 9 d) 0
By default, Word formats bulleted items with a first line indent of ________ and a hanging indent of ________
A) 0.25"; 0.5" B) 0.35"; 0.5" C) 0.5"; 1.0" D) 0.5"; 0.5"
You add a button to the Quick Access Toolbar from the ________ dialog box
A) Excel Options B) Developer C) Commands D) Backstage view
Kelsey and Matt are in the same advanced Access class and have teamed up to help each other understand VBA. In order to prepare for the VBA test, each has created a multiple choice quiz for the other. Some of Kelsey's questions are shown below. Which of the following types of procedures is generally stored in standard modules vs. class modules?a. Functionsb. Subsc. Subroutinesd. Declaration statements
What will be an ideal response?