Java Programming
primer-original-v2mediumJava Programming04 Arrays And Stringsprimer-original-v2

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

Quick AnswerThe correct answer is The program compiles and prints 0 when execute because it directly addresses the core logic of Java Programming.

This question has been retained as-is due to its unique context.

Related Java Programming questions

Practice more Java Programming questions

PrimerPrep has independently reviewed practice questions and coding exercises — all free.