Bird
0
0

Identify the error in the following code snippet:

medium📝 Debug Q6 of 15
Java - Arrays
Identify the error in the following code snippet:
int[][] arr = new int[3][3];
arr[3][0] = 5;
ASyntax error: invalid array declaration
BArrayIndexOutOfBoundsException at runtime
CNo error, code runs fine
DNullPointerException at runtime
Step-by-Step Solution
Solution:
  1. Step 1: Check array size and indexing

    Array has indices 0 to 2 for rows. Accessing arr[3][0] is out of bounds.
  2. Step 2: Identify runtime error

    This causes ArrayIndexOutOfBoundsException at runtime.
  3. Final Answer:

    ArrayIndexOutOfBoundsException at runtime -> Option B
  4. Quick Check:

    Index out of bounds causes runtime exception [OK]
Quick Trick: Array indices go from 0 to length-1 [OK]
Common Mistakes:
  • Using invalid index
  • Confusing compile and runtime errors
  • Assuming no error for out-of-bounds

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes