ProgrammingModerateTCS NQT · Infosys pattern

What is printed?

What is printed?
String s = "ab";
s.concat("cd");
s.toUpperCase();
System.out.print(s);
  1. A. abcd
  2. B. ABCD
  3. C. ab
  4. D. AB

Correct answer: C. ab

Strings are immutable: concat and toUpperCase return new strings, and both results are thrown away because they are not assigned. s still refers to "ab".

More OOP with C++ and Java questions

Exams that ask this topic