Multiple choice technology programming languages

class C { public static void main (String[] a1) { System.out.print(a1[1] + a1[2] + a1[3]); }} What is the result of attempting to compile and run the program? java command A B C

  1. Prints: ABC

  2. Prints BC and Runtime Exception

  3. Prints: BCD

  4. Runtime Exception

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The java command runs with arguments: a1[0]="A", a1[1]="B", and a1[2]="C". The code tries to access a1[1], a1[2], and a1[3]. Accessing a1[3] throws an ArrayIndexOutOfBoundsException at runtime. Prior to the exception, it successfully prints a1[1] ('B') and a1[2] ('C').