To answer this question, let's go through the given code:
public class Q {
public static void main(String argv[]){
int anar[]=new int[]{1,2,3};
System.out.println(anar[1]);
}
}
This code declares an array anar
of type int
and initializes it with the values 1, 2, and 3. The System.out.println(anar[1])
statement prints the value at index 1 of the anar
array.
When you compile and run this code, it will output:
2
Therefore, the correct answer is C) 2.