フリー問題

Java SE 17 Developer のフリー問題 2 / 20 問目

問題文

A developer assigns text that has one leading and one trailing space to a String variable named label, calls label.strip() and then label.replace('a', 'b'), and prints label. What appears on the console?

選択肢

  1. The original text with both of the spaces, because each call gives back a new String and leaves the object that label points at untouched
  2. Nothing appears at all, because the compiler rejects any statement whose String result is discarded without being used in that case
  3. The text without the two spaces but with the letters unchanged, because strip works in place while replace needs its result to be assigned
  4. The text with the letters swapped and without the two spaces, because the two calls change the characters of the variable one after the other in place

解答・解説を確認するには

正解と解説の確認、回答の記録には無料登録が必要です。登録すると演習モードでフリー問題に回答し、正誤と解説をその場で確認できます。