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. Program 1 displays false and Program 2 displays true
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...
When you install an experimental kernel for testing purposes, how do you instruct GRUB not to load it by default?
What will be an ideal response?
Case-Based Critical Thinking QuestionsCase 1-3Your colleague Gina, who has been at the firm for a few months longer than you, offers to give you information about the various views available in Project so that you can determine which of the following will best serve your needs.Your boss now wants you to present remaining durations. What does Gina recommend to you?
A. Schedule Table B. Tracking Table C. Summary Table D. Variance Table
?To add content to Sway from search results, you
A. ?purchase varying data plans from Microsoft. B. ?left-click on the content once. C. ?drag the content right into Sway. D. ?press ALT-F4.
A company is deploying a new two-tier web application in AWS. The company has limited staff and requires high availability, and the application requires complex queries and table joins. Which configuration provides the solution for the company's requirements?
A. MySQL Installed on two Amazon EC2 Instances in a single Availability Zone B. Amazon RDS for MySQL with Multi-AZ C. Amazon ElastiCache D. Amazon DynamoDB