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(((A)a1).equals((A)a2));
}
}
class A {
int x;
public boolean equals(A a) {
return this.x == a.x;
}
}
// Program 2
public class Test {
public static void main(String[] args) {
A a1 = new A();
A 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
a. Program 1 displays true and Program 2 displays true
((A)a1).equals((A)a2) matches the equals(A a) method in the class A.
You might also like to view...
Regular expressions are used in:
a. text editors b. online forms c. IDEs d. all of the above
The active cell is the cell you can currently edit or modify, and it is marked with a(n) black outline.
Answer the following statement true (T) or false (F)
What happened to the child process conhost.exe?
fff
Which of the following statements are correct?
a. new java.math.BigInteger("343"); b. new java.math.BigDecimal("343.445"); c. new java.math.BigInteger(343); d. new java.math.BigDecimal(343.445);