In K @ B book of java5 on page 526 an example of Implementin an equals() method is given.I am getting problem to understand last few lines.
if ((o instanceof Moof) && (((Moof)o).getMoofValue()
== this.moofValue))
i am unable to understand the condition given after '&&'.
this.moofValue means moofvalue ,the current object holds.But what about (((Moof)o).getMoofValue()???
How they are different?/
Complete program is like this------
public class EqualsTest {
public static void main (
String [] args) {
Moof one = new Moof(8);
Moof two = new Moof(8);
if (one.equals(two)) {
System.out.println("one and two are equal");
}
}
}
class Moof {
private int moofValue;
Moof(int val) {
moofValue = val;
}
public int getMoofValue() {
return moofValue;
}
public boolean equals(Object o) {
if ((o instanceof Moof) && (((Moof)o).getMoofValue()
== this.moofValue)) {
return true;
} else {
return false;
}
}
}
Thanks
Deepak