int[] a = {1, 2, 3};
System.out.println(a.length());What happens?
- Acheck_circle
Compilation error
- B
Prints 3
- C
Prints 0
- D
ArrayIndexOutOfBoundsException
Explanation
For arrays, length is a public field, not a method. Writing a.length() (with parentheses) is a compile-time error. Use a.length without parentheses. (Strings use .length(), but arrays use .length.)