KnowledgeBoat Logo
|

Computer Applications

The java statement System.out.println(arr[arr.length]) results in:

Input in Java

2 Likes

Answer

run time error

Reason — In Java, arrays are zero-indexed, meaning the valid indices range from 0 to arr.length - 1. arr.length gives the total number of elements in the array, but accessing arr[arr.length] tries to access an index outside the valid range, resulting in a ArrayIndexOutOfBoundsException at runtime.

Analysing other options:

  1. Logical error: Incorrect because this is not an issue of incorrect logic but an attempt to access an invalid array index.
  2. Syntax error: Incorrect because the code is syntactically valid and compiles without issues.
  3. No error: Incorrect because a runtime error occurs when the code is executed.

Answered By

1 Like


Related Questions