When overriding the equals method, a common mistake is mistyping its signature in the subclass. For example, the equals method is incorrectly written as equals(Circle circle), as shown in (a) in following the code; instead, it should be equals(Object circle), as shown in (b). Show the output of running class Test with the Circle class in (a) and in (b), respectively.
public class Test {
public static void main(String[] args) {
Object circle1 = new Circle();
Object circle2 = new Circle();
System.out.println(circle1.equals(circle2));
}
}
(a)
class Circle {
double radius;
public boolean equals(Circle circle) {
return this.radius == circle.radius;
}
}
(b)
class Circle {
double radius;
public boolean equals(Object circle) {
return this.radius ==
((Circle)circle).radius;
}
}
If Object is replaced by Circle in the Test class, what would be the output to run Test using the Circle class in (a) and (b), respectively?
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.