AllInfoHub Logo

AllInfoHub – MCQ Practice

Variables and Data Types – Multiple Choice Questions (MCQs)

  1. 49. What is the index of the last element of an array of size `n` in Java?

    • A. n
    • B. n-1
    • C. 0
    • D. depends on the array
  2. 50. What happens if you try to access an element at an invalid index in an array in Java?

    • A. It returns null
    • B. It returns 0
    • C. It throws an ArrayIndexOutOfBoundsException
    • D. It creates a new element
  3. 51. What is a multi-dimensional array in Java?

    • A. An array of arrays
    • B. An array that can store elements of different data types
    • C. An array with more than one dimension
    • D. Both A and C
  4. 52. How do you declare a 2D integer array with 3 rows and 4 columns in Java?

    • A. int array[3][4];
    • B. int[][] array = new int[3][4];
    • C. int[3][4] array;
    • D. array int[3][4];