I don't understand line 29, where Good Day is printed twice. Am I right in saying on line 25, that because strInMethod is empty, it clears "result"?
strInMethod is empty
line 25: result = strInMethod;
strInMethod is a new instance of
ResultString class. And the instance variable
str (a
String) is initialized to its default value: null (this is because no value is set, yet). And, both the references "result" and "strInMethod" are pointing to the same object with empty/null values for "str".
Place this statement after line 25 and run the program.
System.out.println(result.str); // this will print null
I don't understand line 29, where Good Day is printed twice.
After line 25:
On line 29 the variable
strInMethod.str is printed. This shows same value as that of the
result.str in the previous line.
EDIT:
Finally, there are no static variables used in the classes, as mentioned in the topic title.
- PrintStrings: All variables are local (method) variables.
- ResultString: All variables are instance variables.
SCJP 5, OCPJP 7, 8, SCJD 5, SCWCD 4, SCBCD 5, SCJWS 4, IBM OOAD 833 & 834, MongoDB Developer