フリー問題

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

問題文

A method has a try block that raises an IllegalStateException, a catch block for that type which returns the value 1, and a finally block that writes one line to the console. What does the method do when it runs?

選択肢

  1. The value 1 reaches the caller at once and the finally block is skipped, because a return inside a handler leaves the method immediately
  2. The exception reaches the caller together with the value 1, because the finally block raises again what the try block raised
  3. The finally block writes its line first because it is scheduled ahead of the handler, and the catch block produces the value 1 after that has happened
  4. The catch block runs first, then the finally block writes its line to the console, and after all of that the value 1 reaches the caller

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

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