Hello there;)
I am currently working my way through different Practice Questions for the OCA Exam.
I recently got this question:
Given:
Then it was asked how many objects have been created here?
The right answer was 4, but I am not quite sure why.
Am I right, that the first String-Object is created here:
String s = "Hello"; //the Object is "Hello"
Then, the second String-Object is created here: s.concat(" World"); //the Object is " World"
Also, the third String-Object ist created here: s.concat(" World"); //the Object is "Hello World"
At last, the fourth String-Object is created here: s.toLowerCase(); //the Object is "hello world"
The System.out.println(s) only prints out "Hello" as String is immutable, right?
Kind regards
Florian