The signature of both the classes is the same but the implementation is different.
For Object class:
public boolean equals(Object obj) {
return (this == obj);
}
For String class the implementation is :
public boolean equals(Object anObject) {
if (this == anObject) {
return true;
}
if (anObject instanceof String) {
String anotherString = (String)anObject;
int n = value.length;
if (n == anotherString.value.length) {
char v1[] = value;
char v2[] = anotherString.value;
int i = 0;
while (n-- != 0) {
if (v1[i] != v2[i])
return false;
i++;
}
return true;
}
}
return false;
}
So when you call the equals method of String object it would call its overrided version of the method i.e implemented inside String class