Code:
public class Test {
  public static void main(String[] args) {
    StringByComposition a = new StringByComposition("announce");
    StringByComposition b = new StringByComposition("announce");
    System.out.println(a.equals(b));
  }
}
class StringByComposition {
  public String composedString;
  public StringByComposition(String s) {
    composedString = s;
  }
}
This code outputs false every time I run I. I constructed the class with identical strings. I thought that two objects of the same class that have all identical fields will be equal to each according to the equals method.

What is going wrong? Please help, although I kinda already knew the answer to my previous question, I have no idea what to do with this one.

--Hold on, when I override the equals method, I get true...
Code:
public class Test {
  public static void main(String[] args) {
    StringByComposition a = new StringByComposition("announce");
    StringByComposition b = new StringByComposition("announce");
    System.out.println(a.equals(b));
  }
}
class StringByComposition {
  public String composedString;
  public StringByComposition(String s) {
    composedString = s;
  }
  public boolean equals(Object o) {
    if (o instanceof StringByComposition) {
      return composedString.equals(((StringByComposition)o).composedString);
    }
    return false;
  }
}
Can some one explain to me why I need to override the equals method?