I am try to compare contents of class object with equals(),but it not give desired output.
so,
How to override equals method in java to desired output ?

Please help me with example...

Uhm, by defining an "equals(Object o)" method in your own class?

Please check this class

class A{
int x;
A(int x){
this.x=x;
}
}
class test11{
public static void main(String as[]){
A a=new A(12);
A a1=new A(12);
System.out.print(a.equals(a1));
}
}

Check it for what?

You didn't implement the equals() method as Masijade already suggested.

Read this if you need a detailed explanation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.