Bird
0
0

Which of the following is the correct way to declare and create an integer array of size 5 in Java?

easy📝 Syntax Q12 of 15
Java - Arrays

Which of the following is the correct way to declare and create an integer array of size 5 in Java?

?
Aint[] arr = int[5];
Bint arr = new int[5];
Cint arr[] = new int();
Dint[] arr = new int[5];
Step-by-Step Solution
Solution:
  1. Step 1: Check array declaration syntax

    In Java, arrays are declared with type[], for example int[]. The new keyword creates the array with size.
  2. Step 2: Validate each option

    int[] arr = new int[5]; uses correct syntax: int[] arr = new int[5]; Options A, B, and C have syntax errors or missing parts.
  3. Final Answer:

    int[] arr = new int[5]; -> Option D
  4. Quick Check:

    Correct array declaration uses new int[size] [OK]
Quick Trick: Use 'type[] name = new type[size];' for arrays [OK]
Common Mistakes:
  • Missing new keyword
  • Wrong brackets placement
  • Using parentheses instead of brackets

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes