When comparing s == s1
you are comparing two different MyString
objects. Think of your situation like this

s
and s1
are different objects, but their attribute point to the same instance of toto
.
They are different objects because of the way you create them:
MyString s = new MyString("toto");
MyString s1 = new MyString("toto");
So s == s1
will return false
. For it to return true
, they had to be the same object. You could achieve it like this:
MyString s = new MyString("toto");
MyString s1 = s;
That would be the result
