since GregorianCalendar doesnot override equals() method.so objects equals() method will use.so == comparion shallow comparison which will just look for both references point to the same object.i thought three would give false.
But how come the answer is true false true.Please help.
What do you think would that print? As you say I'm not overriding the equals method. Given the above case, it takes the equals method from the Object class and prints "Both are not equal". Reason, we are applying equals on two different types (i.e, String and StringBuffer types).
Now consider the below code,
What would the above code print. Here still I'm not overriding the equals method and it will use the one in the Object class. So above code prints Both are equal....Can you spot the difference between the two?? The second case returns true because the equals method makes sure that both the objects are belonging to the same type. This is a similiar situation to your GregorianCalender case where the comparison(equals) is made for the same type i.e. GregorianCalender obj.equals(GregorianCalender obj) which always returns true. Hope you got the idea.