Hi dude,
I'll try to complete the remaining code and I'll give explanation for it.
V1 is a reference variable to Object Valuepair.
V2 is a Object class(Root for all the classes)reference variable pointing to object valuepair.
equals is a method of object class and we are overriding here to check whether the contents of both objects are equal.Whenever we r overriding equals() method,we have to implement hashcode().
class ValuePair
{
public int a,b;
public boolean equals(Object other)
{
try
{
/* Object Casting should take place because the Object class reference variable points to the Object of valuepair*/
ValuePair o=(ValuePair)other;
return(a==o.a && b==o.b) || a==o.b && b==o.a);
}
catch(ClassCastException e)
{
return false;
}
}
public int hashCode()
{
//implementation here.
}
}
public class AppClass
{
public static void main(
String []args)
{
valuepair v1 = new valuepair();
Object v2 = new valuepair();
if (V1.equals(v2))
System.out.println("Both object are equal");
else
System.out.println("Both object are not equal");
}
}