Arrays
- Which of these is an incorrect array declaration?
-
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.
- What is the output of below snippet?
Obj[] names = new String[10];
name[0] = new Integer(0);
-
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.
- What will this code print?
int a[] = new int [10];
System.out.print(a);
-
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].
- Generics does not work with?
-
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.
- What is the type of variable ‘b’ and ‘d’ in the below snippet?
int a[], b;
int []c, d;
-
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.