Programming Language Array in Java Question #2204
Single Choice Not Set

QWhat will be the output?
public class Test{
        public static void main(String[] args){
                int[] a = new int[4];
                a[1] = 1;
                a = new int[2];
                System.out.println("a[1] is " + a[1]);
        }
}

ID: #2204 Array in Java 1,448 views
Question Info
#2204Q ID
Not SetDifficulty
Array in JavaTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A The program has a compile error because new int[2]
  • B The program has a runtime error because a[1]
  • C a[1] is 0
  • D a[1] is 1
Correct Answer

Explanation

a[1] is 0

Share This Question

Challenge a friend or share with your study group.