Array in Java

Programming Language > Java Programming Language

Test your knowledge of Java arrays with these multiple choice questions. Learn about the different types of arrays in Java and how to use them to store and manipulate data. Take the quiz now! ➲ Array in Java - Quiz


  • A objects
  • B object references
  • C primitive data type
  • D None of the above
  • 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
  • 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 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
  • A A copy of the array.
  • B A copy of the first element.
  • C The reference of the array.
  • D The length of the array.
  • A int [] myList = {};
  • B int [] myList = (5, 8, 2);
  • C int myList [] [] = {4,9,7,0};
  • D int myList [] = {4, 3, 7};
  • 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 malloc
  • B alloc
  • C new
  • D new malloc
  • A Arrays can store only objects and not primitive types.
  • B Arrays have a fixed size.
  • C Arrays can be multidimensional.
  • D Elements of an array are accessed using an index.