Arrays


  1. Which of these is an incorrect array declaration?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Operator new must be succeeded by array type and array size. The order is important and determines the type of variable.


  1. What is the output of below snippet?

    Obj[] names = new String[10];
    name[0] = new Integer(0);











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    ArrayIndexOutOfBoundsException comes when code tries to access an invalid index for a given array. ArrayStoreException comes when you have stored an element of type other than the type of array.



  1. What will this code print?

    int a[] = new int [10];
    System.out.print(a);











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    arr is an array variable, it is pointing to array of integers. Printing arr will print garbage value. It is not same as printing arr[0].


  1. Generics does not work with?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Generics gives the flexibility to strongly typecast collections. Generics is applicable to Set, List and Tree. It is not applicable to Array.



  1. What is the type of variable ‘b’ and ‘d’ in the below snippet?

    int a[], b;
    int []c, d;











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    If [] is declared after variable it is applicable only to one variable. If [] is declared before variable it is applicable to all the variables.