I had come across some strange behaviour while i was looking at some java code.
These are as follows:-
1. here is the first observation
The output of this is false but not
str1 == str2
false.can you tell me why?
String str1 = "shobhit";
String str2 = new String("shobhit");
System.out.println("str1 == str2 " + str1 == str2);
2. here goes the second observation
interface abc {
public boolean equals(java.lang.Object arg0);
public void x();
public String toString();
}
public class xyz implements abc{
public void x() {
// TODO Auto-generated method stub
}
}
here interface abc has some object class methods.now class xyz has implemented abc and has not implemented the equals and toString methods.still the compiler does not give error but why?
what is the relation b/w interface and object class.
I found this observation when i tried to implement Comparator interface and did not implement equals method and still did not get any compilation errors.
Can you kindly expalin the reasons for the same.
Thanks in advance