Hi,
Looking at the code below and the result after running the programme.
Here is the result
hash code for str1: -1704812257
hash code for str2: -1704812257
hash code for MyClass obj1: 24216257
hash code for MyClass obj2: 20929799
str1.equals(str2): true
str1 == str2 : false
obj1.equals(obj2): false
obj1 == obj2 : false
Class for str1: class java.lang.String
Class for obj1: class MyClass
Text representation of str1: WhoAmI
Text representation of obj1: MyClass@17182c1
array1 == array2 : false
array1[0] == array2[0] : true
array1[1] == array2[1] : true
array1[2] == array2[2] : true
hash code for MyClass obj3: 16032330
obj1 == obj3 : false
Here are my questions
1. why hash codes of str1 object and str2 object are the same?
2. why hash codes of obj1 and that of obj2 are different?
3. what does equals() method do?
4. what does operator == do?
5. why str1.equals(str2) return true? but str1==str2 returns false?
6. why array1 == array2 return false
7. and why obj1 == obj3 return false even obj3 is cloned from obj1.
Thanks
Sura
