1 . Which of the following are valid array construction?
- int a[] = new int[];
- int a[] = new int[10];
- int a[10] = new int[];
- int a[] = new a[10];
2 . Which of the following are valid array initialization?
- new int[] = {1,2,3,4};
- new int[10] = {1,2,3,4};
- new int[] = 1,2,3,4;
- new int[] = [1,2,3,4];
3 . What will be the output?
public class Test3{ public static void main(String args[]){ int arr[] = new int[10]; int i = 5; arr[i++] = ++i+i++; System.out.print(arr[5]+":"+arr[6]); } }
Choose the one below:
- 14:0
- 0:14
- 0:0
- Compiler Error
4 . What will be the output?
public class Test4{ public static void main(String args[]){ int arr[] = new int[10]; int i = 5; arr[i++] = i+++i++; System.out.print(arr[5]+":"+arr[6]); } }
Choose the one below:
- 13:0
- 14:0
- 0:14
- 0:13
5 . What will be the output?
public class Test5{ static Boolean bl[] = new Boolean[5]; public static void main(String args[]){ System.out.println(bl[0]); } }
Choose the one below:
- Null
- False
- True
- Compiler Error
6 . Which of the following are valid array declarations?
- String[][] a1 = String[20][20];
- String[][] a2 = new String[20,20];
- String[][] a3 = new String[20][20];
- String a4[][] = new String[20][20];
- String[] a5[] = new String[20][20];
7 . Which of the following code correctly creates an array of four initialized string objects?
- String players[] = new String[4];
- String players[] = {“”,””,””,””};
- String players[];
- players = new String[4];
- None of the above
8 . What will be the output?
char[] c = new char[100];
what is the value of c[50]?
Choose the one below:
- 50
- 49
- ‘\u0000’
- ‘\u0020’
9 . which of the following are valid arrays?
- new float[10]={1,2};
- new float[]={1,2};
- new float={1,2};
- None of the above
10 . What will be the output?
public class Test10{ public void method(int arr[]){ arr[0] = 10; } public static void main(String[] args){ int[] small = {1,2,3}; Test10 t= new Test10(); t.method(small); System.out.println(small[0]); } }
Choose the one below:
- 0
- 1
- 0
- None of the above
Answers
1 : 2 is correct. int a[] = new int[10];
2 : 1 is correct. new int[] = {1,2,3,4};
3 : 1 is correct. 14:0
4 : 1 is correct. 13:0
5 : 1 is correct. Null.
6 : 3,4 & 5 is correct.
3 . String[][] a3 = new String[20][20];
4 . String a4[][] = new String[20][20];
5 . String[] a5[] = new String[20][20];
7 : 2 is correct. String players[] = {“”,””,””,””};
8 : 3 is correct. ‘\u0000’
9 : 2 is correct. new float[]={1,2};
10 : 10.