

MCQOPTIONS
Saved Bookmarks
This section includes 20 Mcqs, each offering curated multiple-choice questions to sharpen your Java Programming knowledge and support exam preparation. Choose a topic below to get started.
1. |
What is the output of this program?
|
A. | 1245 |
B. | 12345 |
C. | 123 |
D. | 123450 |
E. | 1234567 |
Answer» F. | |
2. |
What will this code print?
public class array { public static void main(String args[]) { int arr[] = new int [7]; System.out.print(arr); } } |
A. | [I@2a139a55 |
B. | Runtime Error |
C. | 0 0 0 0 0 0 0 |
D. | Compilation error |
E. | None of these |
Answer» B. Runtime Error | |
3. |
What is the output of this program?
public class arr_output { public static void main(String args[]) { char arr_var [] = new char[10]; for (int i = 0; i < 5; ++i) { arr_var[i] = 'K'; System.out.print(arr_var[i] + " "); } } } |
A. | 0 1 2 3 4 5 |
B. | K k k k k |
C. | 1 2 3 4 5 |
D. | i i i i i |
E. | k k k k k k k k k k |
Answer» C. 1 2 3 4 5 | |
4. |
What is the output of this program?
public class output { public static void main(String args[]) { int array[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int num = 10; num = array[array[num] / 2]; System.out.println(array[num] / 2); } } |
A. | 0 |
B. | 1 |
C. | 2 |
D. | 3 |
E. | 4 |
Answer» D. 3 | |
5. |
What is the output of this program?
public class multidimention_arr { public static void main(String args[]) { int array[][] = new int[5][5]; array[0] = new int[1]; array[1] = new int[2]; array[2] = new int[3]; int sum = 0; for (int i = 0; i < 5; ++i) { for (int j = 0; j < i + 1; ++j) { array[i][j] = j + 1; } } for (int i = 0; i < 5; ++i) { for (int j = 0; j < i + 1; ++j) { sum = sum + array[i][j]; } } System.out.print(sum); } } |
A. | 25 |
B. | 10 |
C. | 35 |
D. | 20 |
E. | 30 |
Answer» D. 20 | |
6. |
What is the output of this program?
public class arr_output { public static void main(String args[]) { int arr_var [] = new int[20]; for (int j = 0; j < 20; ++j) { arr_var[j] = j; System.out.print(arr_var[j] + " "); j++; } } } |
A. | 0 2 4 6 8 10 12 14 16 18 |
B. | 2 4 6 8 10 12 14 16 18 |
C. | 2 4 6 8 10 |
D. | 0 2 4 6 8 10 |
E. | 0 1 2 3 4 5 6 7 8 9 10 |
Answer» B. 2 4 6 8 10 12 14 16 18 | |
7. |
What is the output of below snippet?
Obj[] names = new String[10]; name[0] = new Integer(0); |
A. | ArrayIndexOutOfBoundsException |
B. | Compilation Error |
C. | Code runs successfully |
D. | ArrayStoreException |
E. | None of these |
Answer» E. None of these | |
8. |
What will this code print?
int a[] = new int [10]; System.out.print(a); |
A. | Garbage value |
B. | 00000 |
C. | value stored in arr[0]. |
D. | 0 |
E. | None of these |
Answer» B. 00000 | |
9. |
What is the type of variable b and d in the below snippet?
int a[], b; int []c, d; |
A. | b and d are int |
B. | b is int variable; d is int array |
C. | d is int variable; b is int array |
D. | b and d are arrays of type int |
E. | None of these |
Answer» C. d is int variable; b is int array | |
10. |
What is the output of this program?
public class arr_output { public static void main(String args[]) { int arr_var[][] = {{ 1, 2, 3, 4}, { 4 , 5, 6, 7}, { 7, 8, 9, 10}}; int sum = 0; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3 ; ++j) { sum = sum + arr_var[i][j]; } } System.out.print(sum / 2); } } |
A. | 10 |
B. | 15 |
C. | 20 |
D. | 22 |
E. | 12 |
Answer» E. 12 | |
11. |
What is the output of this program?
public class Result { public static void main(String args[]) { boolean p = false; boolean q = true; boolean r = q ^ p; System.out.println(!r); } } |
A. | false |
B. | 0 |
C. | 1 |
D. | true |
E. | None of these |
Answer» B. 0 | |
12. |
What is the output of this program?
public class Result { public static void main(String args[]) { int p , q = 2; p = 20; if (p != 20 && p / 0 == 0) { System.out.println(q); } else { System.out.println(++q); } } } |
A. | 1 |
B. | 2 |
C. | 3 |
D. | 4 |
E. | 5 |
Answer» D. 4 | |
13. |
What is the output of this program?
public class Result { public static void main(String args[]) { int a[] = {5, 6, 7, 9, 11}; for ( int k = 0; k < a.length - 1; ++k) System.out.print(a[k] + " "); } } |
A. | 6 7 9 11 |
B. | 5 6 7 9 |
C. | 1 2 3 4 |
D. | 5 6 7 8 |
E. | None of these |
Answer» C. 1 2 3 4 | |
14. |
What is the output of this program?
public class Result { public static void main(String args[]) { int array1[] = new int[8]; int array2[] = {5, 8, 7, 6, 9}; System.out.println(array1.length + " " + array2.length); } } |
A. | 9 5 |
B. | 5 9 |
C. | 8 5 |
D. | 5 8 |
E. | None of these |
Answer» D. 5 8 | |
15. |
What is the output of this program?
|
A. | 1 |
B. | 2 |
C. | 3 |
D. | 4 |
E. | 5 |
Answer» F. | |
16. |
What is the output of this program?
|
A. | 12345 |
B. | 54321 |
C. | 21345 |
D. | 1345 |
E. | 1234 |
Answer» B. 54321 | |
17. |
What is the output of this program?
|
A. | I |
B. | P |
C. | L |
D. | False |
E. | True |
Answer» F. | |
18. |
Generics does not work with? |
A. | List |
B. | Tree |
C. | Array |
D. | set |
E. | None of these |
Answer» D. set | |
19. |
What is the type of variable b and d in the below snippet? |
A. | b and d are int |
B. | b is int variable; d is int array |
C. | d is int variable; b is int array |
D. | b and d are arrays of type int |
E. | None of these |
Answer» C. d is int variable; b is int array | |
20. |
What will this code print? |
A. | [I@2a139a55 |
B. | Runtime Error |
C. | 0 0 0 0 0 0 0 |
D. | Compilation error |
E. | None of these |
Answer» B. Runtime Error | |