Which two code fragments correctly create and initialize a static array of int elements? (Choose two.)
A.
static final int[] a = { 100,200 };
B.
static final int[] a; static { a=new int[2]; a[0]=100; a[1]=200; }
C.
static final int[] a = new int[2]{ 100,200 };
D.
static final int[] a;
static void init() { a = new int[3]; a[0]=100; a[1]=200; }
A and C are right
You are not right Etibar. A and B are correct just as marked here.
C will not compile because of the number 2 on the right hand side of the expression. A and B compile and run correctly.
That’s right. Options A and B are the answer.
Saludos amigos.
A & B
A and B are correct
C is wrong as dimension expressions can’t be defined with an array initializer
D is wrong as a blank final field may not be initialized.