

MCQOPTIONS
This section includes 219 Mcqs, each offering curated multiple-choice questions to sharpen your Engineering knowledge and support exam preparation. Choose a topic below to get started.
1. |
Where will be the most chance of the garbage collector being invoked?
|
A. | After line 9 |
B. | After line 10 |
C. | After line 11 |
D. | Garbage collector never invoked in |
E. | <i class="java-code">methodA()</i> |
Answer» E. <i class="java-code">methodA()</i> | |
2. |
What will be the output of the program?
|
A. | Finally |
B. | Compilation fails. |
C. | The code runs with no output. |
D. | An exception is thrown at runtime. |
Answer» B. Compilation fails. | |
3. |
Which one is a valid declaration of a boolean? |
A. | boolean b1 = 0; |
B. | boolean b2 = 'false'; |
C. | boolean b3 = false; |
D. | boolean b4 = Boolean.false(); |
E. | boolean b5 = no; |
Answer» D. boolean b4 = Boolean.false(); | |
4. |
Which one of the following will declare an array and initialize it with five numbers? |
A. | Array a = new Array(5); |
B. | int [] a = {23,22,21,20,19}; |
C. | int a [] = new int[5]; |
D. | int [5] array; |
Answer» C. int a [] = new int[5]; | |
5. |
Which three are valid declarations of a float?
|
A. | 1, 2, 4 |
B. | 2, 3, 5 |
C. | 1, 3, 6 |
D. | 2, 4, 6 |
Answer» D. 2, 4, 6 | |
6. |
Which is a valid declarations of a String? |
A. | String s1 = null; |
B. | String s2 = 'null'; |
C. | String s3 = (String) 'abc'; |
D. | String s4 = (String) ' ufeed'; |
Answer» B. String s2 = 'null'; | |
7. |
Which three are legal array declarations?
|
A. | 1, 2, 4 |
B. | 2, 4, 5 |
C. | 2, 3, 4 |
D. | All are correct. |
Answer» B. 2, 4, 5 | |
8. |
Which three are valid declarations of a char?
|
A. | 1, 2, 4 |
B. | 1, 3, 6 |
C. | 3, 5 |
D. | 5 only |
Answer» C. 3, 5 | |
9. |
Which is the valid declarations within an interface definition? |
A. | public double methoda(); |
B. | public final double methoda(); |
C. | static void methoda(double d1); |
D. | protected void methoda(double d1); |
Answer» B. public final double methoda(); | |
10. |
Which three piece of codes are equivalent to line 3?
|
A. | 1, 2 and 3 |
B. | 2, 3 and 4 |
C. | 3, 4 and 5 |
D. | 4, 5 and 6 |
Answer» B. 2, 3 and 4 | |
11. |
Which four options describe the correct default values for array elements of the types indicated?
|
A. | 1, 2, 3, 4 |
B. | 1, 3, 4, 5 |
C. | 2, 4, 5, 6 |
D. | 3, 4, 5, 6 |
Answer» C. 2, 4, 5, 6 | |
12. |
Which one of these lists contains only Java programming language keywords? |
A. | class, if, void, long, Int, continue |
B. | goto, instanceof, native, finally, default, throws |
C. | try, virtual, throw, final, volatile, transient |
D. | strictfp, constant, super, implements, do |
E. | byte, break, assert, switch, include |
Answer» C. try, virtual, throw, final, volatile, transient | |
13. |
What will be the output of the program?
|
A. | 2 |
B. | 4 |
C. | 8 |
D. | 16 |
Answer» C. 8 | |
14. |
What will be the output of the program?
|
A. | -2147483648 and 1 |
B. | 0x80000000 and 0x00000001 |
C. | -2147483648 and -1 |
D. | 1 and -2147483648 |
Answer» B. 0x80000000 and 0x00000001 | |
15. |
Which is a reserved word in the Java programming language? |
A. | method |
B. | native |
C. | subclasses |
D. | reference |
E. | array |
Answer» C. subclasses | |
16. |
Which is a valid keyword in java? |
A. | interface |
B. | string |
C. | Float |
D. | unsigned |
Answer» B. string | |
17. |
What will be the output of the program?
and the command-line invocation is > java CommandArgsThree 1 2 3 |
A. | 0 0 |
B. | 1 2 |
C. | 0 0 0 |
D. | 1 2 3 |
Answer» E. | |
18. |
What will be the output of the program?
and the command-line invocation is > java CommandArgs 1 2 3 4 |
A. | args[2] = 2 |
B. | args[2] = 3 |
C. | args[2] = null |
D. | An exception is thrown at runtime. |
Answer» E. | |
19. |
What will be the output of the program, if this code is executed with the command line: > java F0091 world |
A. | Hello |
B. | Hello Foo91 |
C. | Hello world |
D. | The code does not run. |
Answer» E. | |
20. |
What will be the output of the program?
and the command-line invocation is > java CommandArgsTwo 1 2 3 |
A. | 0 1 2 |
B. | 1 2 3 |
C. | 0 0 0 |
D. | An exception is thrown at runtime |
Answer» E. | |
21. |
In the given program, how many lines of output will be produced?
|
A. | 7 |
B. | 9 |
C. | 11 |
D. | 13 |
E. | Compilation fails |
Answer» D. 13 | |
22. |
What will be the output of the program?
and the command line invocation is > java X a b |
A. | names |
B. | null |
C. | Compilation fails |
D. | An exception is thrown at runtime |
Answer» C. Compilation fails | |
23. |
What will be the output of the program?
|
A. | null |
B. | theDogs |
C. | Compilation fails |
D. | An exception is thrown at runtime |
Answer» E. | |
24. |
What will be the output of the program ?
|
A. | 10, 9, 8, 7, 6, |
B. | 9, 8, 7, 6, 5, |
C. | Compilation fails. |
D. | An exception is thrown at runtime. |
Answer» D. An exception is thrown at runtime. | |
25. |
Which will legally declare, construct, and initialize an array? |
A. | int [] myList = {"1", "2", "3"}; |
B. | int [] myList = (5, 8, 2); |
C. | int myList [] [] = {4,9,7,0}; |
D. | int myList [] = {4, 3, 7}; |
Answer» E. | |
26. |
What will be the output of the program?
|
A. | 12 15 |
B. | 15 15 |
C. | 3 4 5 3 7 5 |
D. | 3 7 5 3 7 5 |
Answer» C. 3 4 5 3 7 5 | |
27. |
What will be the output of the program?
|
A. | true |
B. | false |
C. | Compilation fails |
D. | An exception is thrown at runtime |
Answer» D. An exception is thrown at runtime | |
28. |
What will be the output of the program?
|
A. | 0 |
B. | 7 |
C. | 8 |
D. | 14 |
Answer» E. | |
29. |
What will be the output of the program?
|
A. | ok |
B. | dokey |
C. | ok dokey |
D. | No output is produced |
E. | Compilation error |
Answer» C. ok dokey | |
30. |
What will be the output of the program?
|
A. | BD |
B. | BCD |
C. | BDE |
D. | BCDE |
Answer» D. BCDE | |
31. |
At Point X on line 5, which code is necessary to make the code compile?
|
A. | No code is necessary. |
B. | throws Exception |
C. | catch ( Exception e ) |
D. | throws RuntimeException |
Answer» C. catch ( Exception e ) | |
32. |
Which two statements are true?
|
A. | 1 and 2 |
B. | 3 and 5 |
C. | 4 and 6 |
D. | 1 and 3 |
Answer» D. 1 and 3 | |
33. |
What will be the output of the program?
|
A. | AB |
B. | BC |
C. | ABC |
D. | BCD |
Answer» E. | |
34. |
What will be the output of the program?
|
A. | ABCD |
B. | Compilation fails. |
C. | C is printed before exiting with an error message. |
D. | BC is printed before exiting with an error message. |
Answer» D. BC is printed before exiting with an error message. | |
35. |
When is the B object, created in line 3, eligible for garbage collection?
|
A. | after line 5 |
B. | after line 6 |
C. | after line 7 |
D. | There is no way to be absolutely certain. |
Answer» E. | |
36. |
after line 11 runs, how many objects are eligible for garbage collection?
|
A. | 0 |
B. | 1 |
C. | 2 |
D. | 3 |
Answer» D. 3 | |
37. |
which one create an anonymous inner class from within class Bar?
|
A. | Boo f = new Boo(24) { }; |
B. | Boo f = new Bar() { }; |
C. | Bar f = new Boo(String s) { }; |
D. | Boo f = new Boo.Bar(String s) { }; |
Answer» C. Bar f = new Boo(String s) { }; | |
38. |
What will be the output of the program?
|
A. | 5 2 |
B. | 5 3 |
C. | 6 3 |
D. | 6 4 |
Answer» D. 6 4 | |
39. |
What will be the output of the program?
|
A. | small |
B. | tiny |
C. | huge |
D. | Compilation fails |
Answer» C. huge | |
40. |
Which of the following are legal lines of code?
|
A. | 1 and 2 |
B. | 2 and 3 |
C. | 3 and 4 |
D. | All statements are correct. |
Answer» E. | |
41. |
Which two statements are equivalent?
|
A. | 1 and 2 |
B. | 2 and 4 |
C. | 3 and 4 |
D. | 1 and 3 |
Answer» C. 3 and 4 | |
42. |
What will be the output of the program?
|
A. | slip stream |
B. | slipstream stream |
C. | stream slip stream |
D. | slipstream slip stream |
Answer» E. | |
43. |
What will be the output of the program?
|
A. | true true |
B. | false true |
C. | true false |
D. | false false |
Answer» C. true false | |
44. |
What will be the output of the program?
|
A. | 7 7 |
B. | 7 14 |
C. | 14 0 |
D. | 14 14 |
Answer» C. 14 0 | |
45. |
Which constructs an anonymous inner class instance? |
A. | Runnable r = new Runnable() { }; |
B. | Runnable r = new Runnable(public void run() { }); |
C. | Runnable r = new Runnable { public void run(){}}; |
D. | System.out.println(new Runnable() {public void run() { }}); |
Answer» E. | |
46. |
What will be the output of the program?
|
A. | An exception occurs at runtime at line 10. |
B. | It prints "Zippo". |
C. | Compilation fails because of an error on line 7. |
D. | Compilation fails because of an error on line 13. |
Answer» C. Compilation fails because of an error on line 7. | |
47. |
What will be the output of the program?
|
A. | 57 22 |
B. | 45 38 |
C. | 45 57 |
D. | An exception occurs at runtime. |
Answer» B. 45 38 | |
48. |
What allows the programmer to destroy an object x? |
A. | x.delete() |
B. | x.finalize() |
C. | Runtime.getRuntime().gc() |
D. | Only the garbage collection system can destroy an object. |
Answer» E. | |
49. |
What will be the output of the program?
|
A. | It prints "true". |
B. | It prints "Fred". |
C. | An exception occurs at runtime. |
D. | Compilation fails |
Answer» E. | |
50. |
What will be the output of the program?
|
A. | <i class="java-code">Ex0</i> |
B. | caught |
C. | exception caught |
D. | Compilation fails because of an error at line 2. |
E. | Compilation fails because of an error at line 9. |
Answer» B. caught | |