Return to site

JAVA CERTIFICATION QUESTION: Declaring and initializing one-dimensional arrays in Java

· java,ocp

There are several ways to create an array and initialize an array declaration.

Some can be used anywhere. Others can’t.

 

Which code will print 0 to console? Choose one.

 

A. int arr1[] = new int[10];

System.out.print(arr1[0]);

B. int arr2[10] = new int[10];

System.out.print(arr2[3]);

C. int[] arr3 = new int[0]{};

System.out.print(arr3.length);

D. int[] arr4 = {0,0};

System.out.print(arr4[arr4.length]);

 

 

All Posts
×

Almost done…

We just sent you an email. Please click the link in the email to confirm your subscription!

OK