• Elements in an array are accessed ___

    Elements in an array are accessed ___.
    A) randomly
    B) sequentially
    C) exponentially
    D) logarithmically

    Explanation

    Elements in an array are accessed randomly. In Linked lists, elements are accessed sequentially.
  • In general, the index of the first element in an array is __________

    In general, the index of the first element in an array is __________
    A) 0
    B) -1
    C) 2
    D) 1

    Explanation

    In general, Array Indexing starts from 0. Thus, the index of the first element in an array is 0.
  • Assuming int is of 4bytes, what is the size of int arr[15];?

    Assuming int is of 4bytes, what is the size of int arr[15];?
    A) 15
    B) 19
    C) 11
    D) 60

    Explanation

    Since there are 15 int elements and each int is of 4bytes, we get 15*4 = 60bytes.
  • What are the disadvantages of arrays?

    What are the disadvantages of arrays?
    A) Data structure like queue or stack cannot be implemented
    B) There are chances of wastage of memory space if elements inserted in an array are lesser than the allocated size.
    C) An index value of an array can be negative
    D) Elements are sequentially accessed.

    Explanation

    Arrays are of fixed size. If we insert elements less than the allocated size, unoccupied positions can’t be used again. Wastage will occur in memory.
  • What are the advantages of arrays?

    What are the advantages of arrays?
    A) Objects of mixed data types can be stored
    B) Elements in an array cannot be sorted
    C) Index of the first element of an array is 1
    D) Easier to store elements of same data type

    Explanation

    Arrays stores elements of same data type and present in contiguous memory locations.
  • Which of the following concepts make extensive use of arrays?

    Which of the following concepts make extensive use of arrays?
    A) Binary trees
    B) Scheduling of processes
    C) Caching
    D) Spatial locality

    Explanation

    Whenever a particular memory location is referred, it is likely that the locations nearby are also referred, arrays are stored as contiguous blocks in memory, so if you want to access array elements, spatial locality makes it access quickly.
  • When does the ArrayIndexOutOfBoundsException occur?

    When does the ArrayIndexOutOfBoundsException occur?
    A) Compile-time
    B) Run-time
    C) Not an error
    D) Not an exception at al

    Explanation

    ArrayIndexOutOfBoundsException is a run-time exception and the compilation is error-free.
  • What is the output of the following piece of code?

    What is the output of the following piece of code?

    public class array
    {
    	public static void main(String args[])
    	{
    		int []arr = {1,2,3,4,5};
    		System.out.println(arr[5]);
    	}
    }

    A) 4
    B) 5
    C) ArrayIndexOutOfBoundsException
    D) InavlidInputException

    Explanation

    Trying to access an element beyond the limits of an array gives ArrayIndexOutOfBoundsException.
  • What is the output of the following piece of code?

    What is the output of the following piece of code?

    public class array
    {
    	public static void main(String args[])
    	{
    		int []arr = {1,2,3,4,5};
    		System.out.println(arr[2]);
    		System.out.println(arr[4]);
    	}
    }

    A) 3 and 5
    B) 5 and 3
    C) 2 and 4
    D) 4 and 2

    Explanation

    Array indexing starts from 0.
  • Which of the following is a correct way to declare a multidimensional array in Java?

    Which of the following is a correct way to declare a multidimensional array in Java?
    A) int[] arr;
    B) int arr[[]];
    C) int[][]arr;
    D) int[[]] arr;

    Explanation

    The syntax to declare multidimensional array in java is either int[][] arr; or int arr[][];
Back to top button
Close