Click here to watch in Youtube :
https://www.youtube.com/watch?v=xxz_yf92YRo&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java Tutorial : Java Object Class(equals method-book) |
Java Tutorial : Java Object Class(equals method-book) |
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; } }
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)); } }
childrenStoryBookObj.hashCode() = 1704856573 KidStoryBookObj.hashCode() = 705927765 childrenStoryBookObj.equals(KidStoryBookObj) = false childrenStoryBookObj.equals(childrenStoryBookObj) = true a.equals(b) = true
https://sites.google.com/site/javaee4321/java/ObjectClassDemo_equals_book_App.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/ObjectClassDemo_equals_book_App
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/8fa82bcbf36a8ef675302adced6f7a0764627bd4/BasicJava/ObjectClassDemo_equals_book_App/?at=master
See also:
No comments:
Post a Comment