example of hasCode() method in java




Asked on March 22, 2015
example of hasCode()  method in java


Replied on March 22, 2015
hashCode() and equals() method has been defined in java Object class with default implementation and is used together. When we create our class we can override these two methods. The use of these two methods is to check duplicate object among objects. Two object is same only if hashCode() and equals() methods both are same. Find the example

http://www.concretepage.com/java/hashcode_equals_java


Replied on March 29, 2015
// hashCode test- prints out a hashcode for the abject(a unique id)

public class Tiger {
public static void main(String[] args) {
Tiger t = new Tiger();
System.out.println(t.hashCode());
}

}



Write Answer










©2024 concretepage.com | Privacy Policy | Contact Us