Multiple choice technology architecture

How do you declare and initialize a String array with two elements in a single line of code?

  1. String [] strArr = [“element 1”, “element 2];

  2. String [] strArr = {“element 1”, “element 2”};

  3. String [] strArr = (“element 1”, “element2”);

  4. String [] strArr = new String [“element 1” , “element 2”];

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In Java, array initialization uses curly braces: String[] strArr = {"element 1", "element 2"}; Option A uses square brackets incorrectly. Option C uses parentheses (invalid for arrays). Option D incorrectly uses 'new String[]' with initialization values - should be 'new String[]{...}' or just {...}.