ProgrammingVery hardProduct-company placement · Java

What is printed?

What is printed?
System.out.print("a.b".replace(".", "x") + " " + "a.b".replaceAll(".", "x"));
  1. A. axb axb
  2. B. axb xxx
  3. C. xxx xxx
  4. D. xxx axb

Correct answer: B. axb xxx

replace(CharSequence, CharSequence) works on literal text, but replaceAll interprets its first argument as a regex, where . matches any character.

More OOP with C++ and Java questions

Exams that ask this topic