4 objects will be created.
Two notes:
new String("something")
always creates a new object. The string literal"something"
creates only one object for all occurrences. The best practice is to never usenew String("something")
– the instantiation is redundant.- the concatenation of two strings is transformed to
StringBuilder.append(first).append(second).toString()
, so another object is created here.