You have defined a custom class called Customer with the following code:
public class Customer {
private int id;
private String name;
public Customer(int id, String name) {
= id;
= name;
}
public boolean equals(Object o) {
if (o == this)
return true;
else if (o == null || !(o instanceof Customer))
return false;
Customer c = (Customer)o;
return Objects.equals(id, )
&& Objects.equals(name, );
}
} Two customers are considered equal if they have the same id and name.
How can you compare two customer objects, a and b, and print THEY ARE EQUAL if they are equal? Choose the correct answer:
A. public void printComparison(Customer a, Customer b) {
if (a == b) {
System.out.println("THEY ARE EQUAL");
}
}
B. public void printComparison(Customer a, Customer b) {
if ( (b)) {
System.out.println("THEY ARE EQUAL");
}
}
C. public void printComparison(Customer a, Customer b) {
if (Customer.equals(a, b)) {
System.out.println("THEY ARE EQUAL");
}
}
D. public void printComparison(Customer a, Customer b) {
if (a instanceof b) {
System.out.println("THEY ARE EQUAL");
}
}