Bird
0
0

Identify the error in the following Java array declaration:

medium📝 Debug Q14 of 15
Java - Arrays
Identify the error in the following Java array declaration:
int arr[5];
AArray size cannot be specified in declaration without initialization
BMissing semicolon at the end
CArray must be declared as <code>int arr = new int[5];</code>
DArray size must be a variable, not a number
Step-by-Step Solution
Solution:
  1. Step 1: Understand Java array declaration rules

    In Java, you cannot specify the size inside square brackets during declaration without initialization.
  2. Step 2: Analyze the given code

    int arr[5]; tries to declare an array with size 5 but does not initialize it, which is invalid syntax.
  3. Final Answer:

    Array size cannot be specified in declaration without initialization -> Option A
  4. Quick Check:

    Size only with new keyword = correct [OK]
Quick Trick: Specify size only when using new keyword [OK]
Common Mistakes:
  • Trying to declare size in brackets without new
  • Confusing Java with C/C++ array syntax
  • Forgetting to initialize array after declaration

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes