+ 1
What is the output?
String s="ABC"; s.toLowerCase(); s+="def"; System.out.print(s);
3 ответов
+ 10
answer is ABCdef. String is immutable meaning it cannot be altered, the method toLowerCase() does not change the string it only returns a new string in lowercase:
Further Explanation
public String toLowerCase(String str){
String lower = ......;//However it converts to lowercase
return lower;
}
EDIT: The only way output is abcdef is if code is:
What is the output?
String s="ABC";
s = s.toLowerCase();
s+="def";
System.out.print(s);
That way the variable s is reassigned
0
abcdef
0
abcdef