What is the result?

Given:

What is the result?

Given:

What is the result?

A.
false false

B.
true false

C.
true true

D.
Compilation fails

E.
An exception is thrown at runtime

Explanation:

(this == obj) is the object implementation of equals() and therefore FALSE, if the reference points
to variousobjectsand then the super.equals() is invoked, the object method equals() what still
result in FALSEbetter override of equals() is to compare the attributes like:
public boolean equals (Object obj) {
if (obj != null){
Product p = (Product)obj;
return this.id == p.id;
}
return false;
}



Leave a Reply 1

Your email address will not be published. Required fields are marked *