Array in Java - Quiz

  • A int [] myList = {};
  • B int [] myList = (5, 8, 2);
  • C int myList [] [] = {4,9,7,0};
  • D int myList [] = {4, 3, 7};
  • A objects
  • B object references
  • C primitive data type
  • D None of the above
  • A The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it should be replaced by {1, 2, 3}.
  • B The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it should be replaced by new double[3]{1, 2, 3};
  • C The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it should be replaced by new double[]{1.0, 2.0, 3.0};
  • D The program compiles and runs fine and the output
  • A The program has a compile error because the size of the array wasn't specified when declaring the array.
  • B The program has a runtime error because the array elements are not initialized.
  • C The program runs fine and displays x[0] is 0.
  • D The program has a runtime error because the array element x[0] is not defined.
  • A The code has compile errors because the variable arr cannot be changed once it is assigned.
  • B The code has runtime errors because the variable arr cannot be changed once it is assigned.
  • C The code can compile and run fine. The second line assigns a new array to arr.
  • D The code has compile errors because we cannot assign a different size array to arr.
  • A char[] c = new char();
  • B char[] c = new char[5];
  • C char[] c = new char(4);
  • D char[] c = new char[];
  • A 0
  • B Compilation error, arrays cannot be initialized to zero size.
  • C Compilation error, it is a.length() not a.length
  • D None of the above