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