Java — Which three form part of correct array declarations?

Java Programming Declarations and Access Control Difficulty: Easy
Choose an option
  • A
    public int a [ ]
  • B
    static int [ ] a
  • C
    public [ ] int a
  • D
    private int a [3]
  • E
    private 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

Discussion & Comments
No comments yet. Be the first to comment!
Join Discussion