+ 1

What is the output?

String s="ABC"; s.toLowerCase(); s+="def"; System.out.print(s);

6th Nov 2017, 6:17 PM
Virendra Mishra
Virendra Mishra - avatar
4 Respuestas
+ 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
6th Nov 2017, 7:30 PM
David Akhihiero
David Akhihiero - avatar
0
abcdef
6th Nov 2017, 6:28 PM
Joshua
Joshua - avatar
0
abcdef
7th Nov 2017, 3:52 PM
Rafael R
Rafael R - avatar