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 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...
Which of the following is the correct order of the steps for creating a query in Design view?
A) Add the tables, add the fields, add the criteria, run the query. B) Add the tables, add the criteria, add the fields, run the query. C) Add the criteria, add the fields, add the criteria, run the query. D) Add the fields, add the criteria, add the tables, run the query.
The Paint Bucket Tool is hidden under the ____ Tool on the Tools panel, as shown in the accompanying figure.
a. Motion b. Gradient c. Blending d. Eyedropper
Clicking the Trace Dependents button on the Formula Auditing toolbar will locate cells ____.
A. preceding the active cell B. with formulas that refer to the active cell C. divided by zero D. containing error messages
What does the following expression evaluate to, given that a = 3 and b = 6? (a == b) OR (b > a)
a. True b. False c. NOT d. cannot tell