

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.
51. |
Which two can be used to create a new Thread?
|
A. | 1 and 2 |
B. | 2 and 3 |
C. | 1 and 4 |
D. | 3 and 4 |
Answer» D. 3 and 4 | |
52. |
The following block of code creates a Thread using a Runnable target:
Which of the following classes can be used to create the target, so that the preceding code compiles correctly?
|
A. | public class MyRunnable extends Runnable{public void run(){}} |
B. | public class MyRunnable extends Object{public void run(){}} |
C. | public class MyRunnable implements Runnable{public void run(){}} |
D. | public class MyRunnable implements Runnable{void run(){}} |
Answer» D. public class MyRunnable implements Runnable{void run(){}} | |
53. |
What will be the output of the program?
|
A. | AC |
B. | BC |
C. | ACD |
D. | ABCD |
Answer» D. ABCD | |
54. |
Which statement is true about assertions in the Java programming language? |
A. | Assertion expressions should not contain side effects. |
B. | Assertion expression values can be any primitive type. |
C. | Assertions should be used for enforcing preconditions on public methods. |
D. | An AssertionError thrown as a result of a failed assertion should always be handled by the enclosing method. |
Answer» B. Assertion expression values can be any primitive type. | |
55. |
which two of the following statements, inserted independently, could legally be inserted into missing section of this code?
|
A. | 1 and 4 |
B. | 2 and 3 |
C. | 1 and 3 |
D. | 2 and 4 |
Answer» E. | |
56. |
and given that all methods of class FileOutputStream, including close(), throw an IOException, which of these is true?
|
A. | This program will compile successfully. |
B. | This program fails to compile due to an error at line 4. |
C. | This program fails to compile due to an error at line 6. |
D. | This program fails to compile due to an error at line 18. |
Answer» E. | |
57. |
Which three statements are true?
|
A. | 1, 2 and 4 |
B. | 2, 3 and 5 |
C. | 3, 4 and 5 |
D. | 1, 2 and 5 |
Answer» C. 3, 4 and 5 | |
58. |
which statement, inserted at line 10, creates an instance of Bar?
|
A. | Foo.Bar b = new Foo.Bar(); |
B. | Foo.Bar b = f.new Bar(); |
C. | Bar b = new f.Bar(); |
D. | Bar b = f.new Bar(); |
Answer» C. Bar b = new f.Bar(); | |
59. |
and given that EOFException and FileNotFoundException are both subclasses of IOException, and further assuming this block of code is placed into a class, which statement is most true concerning this code?
|
A. | The code will not compile. |
B. | Code output: Start Hello world File Not Found. |
C. | Code output: Start Hello world End of file exception. |
D. | Code output: Start Hello world Catch Here File not found. |
Answer» B. Code output: Start Hello world File Not Found. | |
60. |
Which is true about an anonymous inner class? |
A. | It can extend exactly one class and implement exactly one interface. |
B. | It can extend exactly one class and can implement multiple interfaces. |
C. | It can extend exactly one class or implement exactly one interface. |
D. | It can implement multiple interfaces regardless of whether it also extends a class. |
Answer» D. It can implement multiple interfaces regardless of whether it also extends a class. | |
61. |
which statement, if placed in a class other than MyOuter or MyInner, instantiates an instance of the nested class?
|
A. | MyOuter.MyInner m = new MyOuter.MyInner(); |
B. | MyOuter.MyInner mi = new MyInner(); |
C. | <p>MyOuter m = new MyOuter();</p> |
D. | <p>MyOuter.MyInner mi = m.new MyOuter.MyInner();</p> |
E. | MyInner mi = new MyOuter.MyInner(); |
Answer» B. MyOuter.MyInner mi = new MyInner(); | |
62. |
What will be the output of the program?
|
A. | foo |
B. | MyThread foo |
C. | MyThread bar |
D. | foo bar |
Answer» C. MyThread bar | |
63. |
Which four can be thrown using the throw statement?
|
A. | 1, 2, 3 and 4 |
B. | 2, 3, 4 and 5 |
C. | 1, 4, 5 and 6 |
D. | 2, 4, 5 and 6 |
Answer» D. 2, 4, 5 and 6 | |
64. |
Which two are equal?
|
A. | 1 and 2 |
B. | 2 and 4 |
C. | 1 and 3 |
D. | 2 and 3 |
Answer» C. 1 and 3 | |
65. |
What will be the output of the program?
|
A. | null null 42 |
B. | 0 0 42 |
C. | 0 42 42 |
D. | 0 0 0 |
Answer» D. 0 0 0 | |
66. |
What will be the output of the program?
|
A. | finished |
B. | Exception |
C. | Compilation fails. |
D. | Arithmetic Exception |
Answer» D. Arithmetic Exception | |
67. |
What will be the output of the program?
|
A. | Compilation fails. |
B. | An error occurs at runtime. |
C. | It prints "foobarhi" |
D. | It prints "barhi" |
Answer» D. It prints "barhi" | |
68. |
After line 8 runs. how many objects are eligible for garbage collection?
|
A. | 0 |
B. | 1 |
C. | 2 |
D. | 3 |
Answer» C. 2 | |
69. |
What will be the output of the program?
|
A. | finally |
B. | exception finished |
C. | finally exception finished |
D. | Compilation fails |
Answer» D. Compilation fails | |
70. |
Which is true about a method-local inner class? |
A. | It must be marked final. |
B. | It can be marked abstract. |
C. | It can be marked public. |
D. | It can be marked static. |
Answer» C. It can be marked public. | |
71. |
What will be the output of the program?
|
A. | Prints "Inside Thread Inside Thread" |
B. | Prints "Inside Thread Inside Runnable" |
C. | Does not compile |
D. | Throws exception at runtime |
Answer» B. Prints "Inside Thread Inside Runnable" | |
72. |
What will be the output of the program?
|
A. | Compilation fails |
B. | An exception occurs at runtime. |
C. | It prints "Thread one. Thread two." |
D. | The output cannot be determined. |
Answer» C. It prints "Thread one. Thread two." | |
73. |
What will be the output of the program?
|
A. | 9 7 7 foo 7 7foo |
B. | 72 34 34 foo34 34foo |
C. | 9 7 7 foo34 34foo |
D. | 72 7 34 foo34 7foo |
Answer» E. | |
74. |
What will be the output of the program?
|
A. | count = 0 |
B. | count = 2 |
C. | count = 3 |
D. | count = 4 |
Answer» D. count = 4 | |
75. |
Which two statements are equivalent?
|
A. | 1 and 2 |
B. | 2 and 3 |
C. | 3 and 4 |
D. | 1 and 4 |
Answer» D. 1 and 4 | |
76. |
When is the Float object, created in line 3, eligible for garbage collection?
|
A. | just after line 5 |
B. | just after line 6 |
C. | just after line 7 |
D. | just after line 8 |
Answer» D. just after line 8 | |
77. |
What will be the output of the program?
|
A. | 5 3 |
B. | 8 2 |
C. | 8 3 |
D. | 8 5 |
Answer» C. 8 3 | |
78. |
which three statements are true?
|
A. | 1, 2 and 3 |
B. | 2, 4 and 5 |
C. | 3, 4 and 5 |
D. | 1, 4 and 5 |
Answer» C. 3, 4 and 5 | |
79. |
What will be the output of the program?
|
A. | Nothing. The program will not compile because no exceptions are specified. |
B. | Nothing. The program will not compile because no catch clauses are specified. |
C. | Hello world. |
D. | Hello world Finally executing |
Answer» E. | |
80. |
What will be the output of the program?
|
A. | Compilation fails. |
B. | 1..2..3.. |
C. | 0..1..2..3.. |
D. | 0..1..2.. |
Answer» E. | |
81. |
What will be the output of the program?
|
A. | ABBCAD |
B. | ABCBCAD |
C. | CDADACB |
D. | Output determined by the underlying platform. |
Answer» E. | |
82. |
What will be the output of the program?
|
A. | It will print the numbers 0 to 19 sequentially |
B. | It will print the numbers 1 to 20 sequentially |
C. | It will print the numbers 1 to 20, but the order cannot be determined |
D. | The code will not compile. |
Answer» C. It will print the numbers 1 to 20, but the order cannot be determined | |
83. |
What will be the output of the program?
|
A. | DeadLock |
B. | It print 12 12 12 12 |
C. | Compilation Error |
D. | Cannot determine output. |
Answer» C. Compilation Error | |
84. |
What will be the output of the program?
|
A. | This code will not compile due to line 5. |
B. | This code will not compile due to line 6. |
C. | 1..2.. |
D. | 1..2..3.. |
Answer» D. 1..2..3.. | |
85. |
What is the name of the method used to start a thread execution? |
A. | init(); |
B. | start(); |
C. | run(); |
D. | resume(); |
Answer» C. run(); | |
86. |
What will be the output of the program?
|
A. | 0 2 4 |
B. | 0 2 4 5 |
C. | 0 1 2 3 4 |
D. | Compilation fails. |
Answer» E. | |
87. |
What will be the output of the program?
|
A. | x = 1 |
B. | x = 3 |
C. | Compilation fails. |
D. | The code runs with no output. |
Answer» D. The code runs with no output. | |
88. |
What will be the output of the program?
|
A. | Zero |
B. | Twelve |
C. | Default |
D. | Compilation fails |
Answer» E. | |
89. |
What will be the output of the program?
|
A. | i = 0 |
B. | i = 3 |
C. | i = 4 |
D. | Compilation fails. |
Answer» E. | |
90. |
What will be the output of the program?
|
A. | ABDCBDCB |
B. | ABCDABCD |
C. | Compilation fails. |
D. | An exception is thrown at runtime. |
Answer» B. ABCDABCD | |
91. |
What will be the output of the program?
|
A. | 0 1 2 |
B. | 0 1 2 1 2 2 |
C. | Compilation fails at line 11. |
D. | Compilation fails at line 12. |
Answer» D. Compilation fails at line 12. | |
92. |
What will be the output of the program?
|
A. | 41 |
B. | 42 |
C. | 50 |
D. | 51 |
Answer» E. | |
93. |
What will be the output of the program?
|
A. | I is 1 |
B. | I is 1 I is 1 |
C. | No output is produced. |
D. | Compilation error |
Answer» D. Compilation error | |
94. |
What will be the output of the program?
|
A. | x = 6 y = 0 |
B. | x = 7 y = 0 |
C. | x = 6 y = -1 |
D. | Compilation fails. |
Answer» E. | |
95. |
What will be the output of the program?
|
A. | 1 |
B. | 2 |
C. | 3 |
D. | 4 |
Answer» B. 2 | |
96. |
What will be the output of the program?
|
A. | j = 0 |
B. | j = 2 |
C. | j = 4 |
D. | j = 6 |
Answer» E. | |
97. |
What will be the output of the program?
|
A. | a |
B. | b |
C. | c |
D. | d |
Answer» D. d | |
98. |
What will be the output of the program?
|
A. | 0 def 1 |
B. | 2 1 0 def 1 |
C. | 2 1 0 def def |
D. | 2 1 0 def 1 def 1 |
Answer» E. | |
99. |
What will be the output of the program?
|
A. | i = 1, j = 0 |
B. | i = 1, j = 4 |
C. | i = 3, j = 4 |
D. | Compilation fails. |
Answer» E. | |
100. |
What will be the output of the program?
|
A. | done |
B. | one two done |
C. | one two three done |
D. | one two three two three done |
Answer» E. | |