Ok, so what happens when you do this.
A a1=new A();
A a2=new A();
A a3=new A();
I upload two pictures on how I imagine it being like. Can you
First picture is true for Strings
( due to string pooling, an optimisation for strings known to be identical at compile time):
String a1="s";
String a2="s";
String a3="s";
The second one is true for:
A a1=new A();
A a2=new A();
A a3=new A();
If you want behaviour like String
has - you should implement Flyweight pattern.