Bird
0
0

Which of the following is the correct syntax to declare and initialize an integer array with values 1, 2, 3 in Java?

easy📝 Syntax Q3 of 15
Java - Arrays

Which of the following is the correct syntax to declare and initialize an integer array with values 1, 2, 3 in Java?

Aint[] arr = {1, 2, 3};
Bint arr = {1, 2, 3};
Cint[] arr = new int[3] = {1, 2, 3};
Dint arr[] = new int{1, 2, 3};
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct array declaration syntax

    In Java, arrays are declared with type[], and can be initialized with curly braces containing values.
  2. Step 2: Check each option for syntax correctness

    int[] arr = {1, 2, 3}; uses correct syntax: int[] arr = {1, 2, 3};. Others have syntax errors.
  3. Final Answer:

    int[] arr = {1, 2, 3}; -> Option A
  4. Quick Check:

    Array declaration with values uses type[] and braces [OK]
Quick Trick: Use type[] and braces to initialize arrays [OK]
Common Mistakes:
  • Missing [] after type
  • Trying to assign values with new and braces together incorrectly
  • Declaring array without []

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes