What is the difference between creating Object, for example in my code, type Obj with operator "new" and Object type String?
public class Objs {
int a;
public Objs(int a)
{
this.a = a;
}
public static void main(String[] args)
{
String str = new String("Hello");
String str1 = str; // (str1 == str) == true
str += ", world!!"; // after this (str1 == str) == false - Why?
Objs o = new Objs(4);
Objs o1 = o; //(o == o1) == true
o.a += 9; // after this (o == o1) == true also
}
}
Why after I'm changing value of "str", references "str" and "str1" become not equal, but if I'm doing the same with class Obj references stay equal?