Java — Which three form part of correct array declarations?
Java Programming
Declarations and Access Control
Difficulty: Easy
Choose an option
-
Apublic int a [ ]
-
Bstatic int [ ] a
-
Cpublic [ ] int a
-
Dprivate int a [3]
-
Eprivate int [3] a [ ]
Answer
Correct Answer: public int a[], static int[] a, public final int[] a
Explanation
Introduction / Context:This question checks the syntax for correct array declarations in Java.
Concept / Approach:In Java arrays:
- The brackets [] must follow either the type or the variable, but not the access modifier directly.
- Array size cannot be given at declaration (e.g., int a[3] is invalid in Java).
Step-by-Step:
Option A: Valid declaration.Option B: Valid declaration.Option C: Invalid syntax.Option D: Invalid (size not allowed in declaration).Option E: Invalid (size inside brackets not allowed in declaration).Final Answer:1, 2, and 6