Mock Exam – Arrays |
Q1 | Which of the following are valid array construction? |
A1 | int a[] = new int[]; |
A2 | int a[] = new int[10]; |
A3 | int a[10] = new int[]; |
A4 | int a[] = new a[10]; |
Q2 | Which of the following are valid array initialization? |
A1 | new int[] = {1,2,3,4}; |
A2 | new int[10] = {1,2,3,4}; |
A3 | new int[] = 1,2,3,4; |
A4 | new int[] = [1,2,3,4]; |
Q3 | 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]); } } What will be the output? |
A1 | 14:0 |
A2 | 0:14 |
A3 | 0:0 |
A4 | Compiler Error |
Q4 | 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]); } } What will be the output? |
A1 | 13:0 |
A2 | 14:0 |
A3 | 0:14 |
A4 | 0:13 |
Q5 | public class Test5{ static Boolean bl[] = new Boolean[5]; public static void main(String args[]){ System.out.println(bl[0]); } } What will be the output? |
A1 | null |
A2 | false |
A3 | true |
A4 | Compiler Error |
Q6 | Which of the following are valid array declarations? |
A1 | String[][] a1 = String[20][20]; |
A2 | String[][] a2 = new String[20,20]; |
A3 | String[][] a3 = new String[20][20]; |
A4 | String a4[][] = new String[20][20]; |
A5 | String[] a5[] = new String[20][20]; |
Q7 | Which of the following code correctly creates an array of four initialized string objects?. |
A1 | String players[] = new String[4]; |
A2 | String players[] = {“”,””,””,””}; |
A3 | String players[];
|
A4 | None of the above. |
Q8 | char[] c = new char[100];
|
A1 | 50 |
A2 | 49 |
A3 | ‘\u0000’ |
A4 | ‘\u0020’ |
Q9 | which of the following are valid arrays? |
A1 | new float[10]={1,2}; |
A2 | new float[]={1,2}; |
A3 | new float={1,2}; |
A4 | none of the above |
Q10 | 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]); } } what will be the output? |
A1 | 0 |
A2 | 1 |
A3 | 0 |
A4 | none of the above |
Answers |
1 | A2)int a[] = new int[10]; |
2 | A1)new int[] = {1,2,3,4}; |
3 | A1)14:0 |
4 | A1)13:0 |
5 | A1)null |
6 | A3 : String[][] a3 = new String[20][20]; A4 : String a4[][] = new String[20][20]; A5 : String[] a5[] = new String[20][20]; |
7 | A2 : String players[] = {“”,””,””,””}; |
8 | c) ‘\u0000’ |
9 | b)new float[]={1,2}; |
10 | 10 |