フリー問題

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

問題文

A method declares an array of five String values and an array of five boolean values, and it reads element three of each array before assigning anything. What does the method observe, and what happens if it needs a sixth slot later?

選択肢

  1. It observes a null reference and the value false, and a sixth slot calls for a brand new array because the length of an array is fixed once it is created
  2. It fails to compile on both reads, because the compiler tracks that the elements have not been assigned yet
  3. It fails at run time on both reads, because reading an element that has never been assigned raises an exception for every array type
  4. It observes an empty text and the value false, and a sixth slot is added by assigning to index five because an array grows on demand like a list does

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

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