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(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
b In Program 1, the equals method in the Object class is invoked. In Program 2, the equals method in the class A is invoked. There are now two overloaded methods available in the class A. i.e. public boolean equals(Object a) and public boolean equals(A a). Which of the two is used by a1.equals(a2) is determined at compile time. a1.equals(a2) in Program 1 matches the equals method defined in Object and a1.equals(a2) in Program 2 matches the equals method defined in the class A.
You might also like to view...
The purpose of the __________ algorithm is to enable two users to securely reach agreement about a shared secret that can be used as a secret key for subsequent symmetric encryption of messages.
Fill in the blank(s) with the appropriate word(s).
The __________ directive is used to declare a symbol which is not defined anywhere in the module being assembled, but is assumed to be defined in some other module and needs to be referred to by this one.
A. [WARNING] B. EXTERN C. SECTION D. COMMON