public class Book
{
private String name;
private String isbnNumber;
public Book(String name, String isbnNumber)
{
super();
this.name = name;
this.isbnNumber = isbnNumber;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getIsbnNumber()
{
return isbnNumber;
}
public void setIsbnNumber(String isbnNumber)
{
this.isbnNumber = isbnNumber;
}
}
ObjectClassTest.java public class ObjectClassTest
{
public static void main(String[] args)
{
Book childrenStoryBookObj = new Book("Children Story", "2000");
Book KidStoryBookObj = new Book("Kids Story", "2000");
System.out.println("childrenStoryBookObj.hashCode() = "
+ childrenStoryBookObj.hashCode());
System.out.println("KidStoryBookObj.hashCode() = "
+ KidStoryBookObj.hashCode());
/*
* The equals() method provided in the Object class
* uses the identity operator (==) to determine
* whether two objects are equal.
*
* For objects, The equals() method provided by
* Object tests whether the object references are
* equal—that is, if the objects compared are the
* exact same object.
*/
System.out
.println("childrenStoryBookObj.equals(KidStoryBookObj) = "
+ childrenStoryBookObj
.equals(KidStoryBookObj));
System.out
.println("childrenStoryBookObj.equals(childrenStoryBookObj) = "
+ childrenStoryBookObj
.equals(childrenStoryBookObj));
Integer a = 10;
Integer b = 10;
/*
* For primitive data types,it won't check the
* Object reference.
*/
System.out.println("a.equals(b) = " + a.equals(b));
}
}