Java Programming
Accenture PrimermediumJava Programming04 Arrays And Strings

Accenture Java Programming Practice Question

class TestArray { public static void main(String args[]) { int arr_sample[] = new int[2]; System.out.println(arr_sample[0]); } } What will be the result of compiling and executing the above code?

Answer options

A
The program does not compile because arr_sample[0] is being read before being initialize
B
The program generates a runtime exception because arr_sample[0] is being read before being initialize
C
The program compiles and prints 0 when execute
D
The program compiles and prints 1 when execute
E
The program compiles and runs but the results are not predictable because of un-initialized memory being rea

Correct answer: The program compiles and prints 0 when execute

Explanation

Correct answer: The program compiles and prints 0 when execute.

Related Accenture Java Programming questions

Practice more Accenture Java Programming questions

PrimerDumps has 1400+ primer questions, 2026 mocks and coding hands-on — all free.