object equals method in java example

Published: 14 February 2017
on channel: Inside App
986
3

The equals() method compares two objects for equality and returns true if they are equal. The equals() method provided in the Object class uses the identity operator ( == ) to determine whether two objects are equal. For primitive data types, this gives the correct result.
=======================================================================================
// (Object.equals)
class Rect
{
int l,b;
int area()
{
return l*b;
}
Rect(int l,int b)
{
this.l=l;
this.b=b;
}
public boolean equals(Rect obj)
{
if(this.area()==obj.area())
{
return true;
}
else
{
return false;
}
}
public static void main(String []s)
{
Rect r1=new Rect(3,8);
Rect r2=new Rect(6,4);
System.out.println(r1.equals(r2));

}
}

=======================================================================================
Searches related to object class in equals methods,
hashcode method in java,
java hashcode equals,
java hashcode example,
java object equals vs ==,
what is the use of hashcode in java,
java object equals method override,
equals and hashcode contract,
object equals method in java example

www.readranks.com
www.patelwala.com

~-~~-~~~-~~-~
Please watch: "How to online money earn from Flipkart without selling any products"
   • Video  
~-~~-~~~-~~-~


On this page of the site you can watch the video online object equals method in java example with a duration of hours minute second in good quality, which was uploaded by the user Inside App 14 February 2017, share the link with friends and acquaintances, this video has already been watched 986 times on youtube and it was liked by 3 viewers. Enjoy your viewing!