Multiple choice technology programming languages

Which two cause a compiler error?

  1. int[] scores = {3, 5, 7};

  2. int [][] scores = {2,7,6}, {9,3,45};

  3. String cats[] = {“Fluffy”, “Spot”, “Zeus”};

  4. boolean results[] = new boolean [3] {true, false, true};

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

Option A is valid 1D array initialization. Option B has two errors: missing inner braces for 2D structure, and incorrect syntax - should be {{2,7,6}, {9,3,45}}. Option C is valid String array. Option D is invalid - cannot specify size [3] when using array initialization syntax; either use new boolean[3] or the initialization syntax, not both.