MCQ Single Best Answer Not Set

QAnalyze the following code and choose the correct answer.
int[] arr = new int[5];
arr = new int[6];

ID: #2203 Array in Java 4,627 views
Question Info
#2203Q ID
Not SetDifficulty
Array in JavaTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A The code has compile errors because the variable arr cannot be changed once it is assigned.
  • B The code has runtime errors because the variable arr cannot be changed once it is assigned.
  • C The code can compile and run fine. The second line assigns a new array to arr.
  • D The code has compile errors because we cannot assign a different size array to arr.
Correct Answer: Option C

Explanation

The code can compile and run fine. The second line assigns a new array to arr.

Share This Question

Challenge a friend or share with your study group.