public class MainClass {
public static void main (String [] args) {
MyClass one = new MyClass(8);
MyClass two = new MyClass(8);
if (one.equals(two)) {
System.out.println("one and two are equal");
}
}
}
class MyClass {
private int moofValue;
MyClass(int val) {
moofValue = val;
}
public int getMyClassValue() {
return moofValue;
}
public boolean equals(Object o) {
if ((o instanceof MyClass) && (((MyClass)o).getMyClassValue()
== this.moofValue)) {
return true;
} else {
return false;
}
}
}
|