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 In Program 1, ((A)a1).equals((A)a2) matches the equals(A a) method in the class A.

Computer Science & Information Technology

You might also like to view...

Network administrators are sometimes called network ________

Fill in the blank(s) with correct word

Computer Science & Information Technology

The table or tables from which a query gets its data are referred to as the query's data ________

Fill in the blank(s) with correct word

Computer Science & Information Technology