Question 43 / 90:  Which code example makes use of arrays without producing a compiler or runtime error?
A  public class Actor { String[] characterName = new String[3]; { characterName[0]
= "Captain Video"; characterName[1] = "Quizmaster"; characterName[2]
= "J.C. Money"; characterName[3] = "Jersey Joe"; } }
B  public class Actor { String[] characterName = new String[1..4]; { characterName[0]
= "Captain Video"; characterName[1] = "Quizmaster"; characterName[2]
= "J.C. Money"; characterName[3] = "Jersey Joe"; } }
C  public class Actor { String characterName = new String[4]; { characterName[0]
= "Captain Video"; characterName[1] = "Quizmaster"; characterName[2]
= "J.C. Money"; characterName[3] = "Jersey Joe"; } }
D  public class Actor { String[] characterName = new String[4]; { characterName[0]
= "Captain Video"; characterName[1] = "Quizmaster"; characterName[2]
= "J.C. Money"; characterName[3] = "Jersey Joe"; } }
<< First < Previous Flashcard Next > Last >>
Explanation:

D. The array declaration and element assignments are used appropriately and compile without error.

A, B, and C are incorrect.

A compiles with an ArrayIndexOutOfBoundsException exception thrown at runtime.

This is because the array index characterName[3] is out of bounds.

B fails to compile because only an integer is expected in the box brackets.

C fails to compile because the box brackets that are needed to create the array are missing.

Exam Home Page
https://www.jobilize.com/quiz-my-oca-mock-exam-by-mike-wolf

My OCA Mock

Author:

Access: Public Instant Grading

Ask
Michael Sag
Start Exam
Copy and paste the following HTML code into your website or blog.
<iframe src="https://www.jobilize.com/embed/quiz-my-oca-mock-exam-by-mike-wolf" width="600" height="600" frameborder="0" marginwidth="0" marginheight="0" scrolling="yes" style="border:1px solid #CCC; border-width:1px 1px 0; margin-bottom:5px" allowfullscreen webkitallowfullscreen mozallowfullscreen> </iframe>