

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.
101. |
What will be the output of the program?
|
A. | f[0] = 0 |
B. | f[0] = 0.0 |
C. | Compile Error |
D. | Runtime Exception |
Answer» C. Compile Error | |
102. |
What will be the output of the program?
|
A. | Prints: false,false,false |
B. | Prints: false,false,true |
C. | Prints: false,true,false |
D. | Prints: true,false,false |
Answer» E. | |
103. |
What will be the output of the program?
|
A. | one two three four |
B. | four three two one |
C. | four one three two |
D. | one two three four one |
Answer» D. one two three four one | |
104. |
What will be the output of the program?
|
A. | 42 |
B. | Runtime Exception |
C. | Compile Error at line 2 |
D. | Compile Error at line 5 |
Answer» B. Runtime Exception | |
105. |
What will be the output of the program?
|
A. | I is 0 |
B. | I is 0 I is 1 |
C. | Compilation fails. |
D. | None of the above |
Answer» D. None of the above | |
106. |
What will be the output of the program?
|
A. | j = -1 |
B. | j = 0 |
C. | j = 1 |
D. | Compilation fails. |
Answer» E. | |
107. |
What will be the output of the program?
|
A. | value = 2 |
B. | value = 4 |
C. | value = 6 |
D. | value = 8 |
Answer» E. | |
108. |
What will be the output of the program?
|
A. | 0 |
B. | 1 |
C. | 101 |
D. | 111 |
Answer» D. 111 | |
109. |
What will be the output of the program?
|
A. | 0 |
B. | null |
C. | Compile Error |
D. | <i class="java-code">NullPointerException</i> |
E. | at runtime |
Answer» E. at runtime | |
110. |
What will be the output of the program?
|
A. | Prints: false, false, false |
B. | Prints: false, false, true |
C. | Prints: false, true, false |
D. | Prints: false, true, true |
Answer» D. Prints: false, true, true | |
111. |
What will be the output of the program?
|
A. | Compilation will succeed. |
B. | Compilation will fail at line 3. |
C. | Compilation will fail at line 5. |
D. | Compilation will fail at line 15. |
Answer» C. Compilation will fail at line 5. | |
112. |
What will be the output of the program?
And the command line invocation: > java Test red green blue |
A. | baz = |
B. | baz = null |
C. | baz = blue |
D. | Runtime Exception |
Answer» E. | |
113. |
What will be the output of the program?
|
A. | NULL |
B. | Compile Error |
C. | Code runs but no output |
D. | Runtime Exception |
Answer» C. Code runs but no output | |
114. |
What will be the output of the program?
|
A. | 0 1 2 |
B. | 0 1 2 1 2 2 |
C. | 2 1 0 1 0 0 |
D. | 2 1 2 0 1 2 |
Answer» E. | |
115. |
What will be the output of the program?
|
A. | i = 6 and j = 5 |
B. | i = 5 and j = 5 |
C. | i = 6 and j = 4 |
D. | i = 5 and j = 6 |
Answer» E. | |
116. |
Which two are valid constructors for Thread?
|
A. | 1 and 3 |
B. | 2 and 4 |
C. | 1 and 2 |
D. | 2 and 5 |
Answer» D. 2 and 5 | |
117. |
Which of the following line of code is suitable to start a thread ?
|
A. | Thread t = new Thread(X); |
B. | Thread t = new Thread(X); t.start(); |
C. | X run = new X(); Thread t = new Thread(run); t.start(); |
D. | Thread t = new Thread(); x.run(); |
Answer» D. Thread t = new Thread(); x.run(); | |
118. |
Which three are methods of the Object class?
|
A. | 1, 2, 4 |
B. | 2, 4, 5 |
C. | 1, 2, 6 |
D. | 2, 3, 4 |
Answer» D. 2, 3, 4 | |
119. |
Which two are acceptable types for x?
|
A. | 1 and 3 |
B. | 2 and 4 |
C. | 3 and 5 |
D. | 4 and 6 |
Answer» B. 2 and 4 | |
120. |
Which statement is true?
|
A. | Compilation fails. |
B. | "odd" will always be output. |
C. | "even" will always be output. |
D. | "odd" will be output for odd values of x, and "even" for even values. |
Answer» B. "odd" will always be output. | |
121. |
Which statement is true?
|
A. | There is a syntax error on line 1. |
B. | There are syntax errors on lines 1 and 6. |
C. | There are syntax errors on lines 1, 6, and 8. |
D. | There is a syntax error on line 6. |
Answer» E. | |
122. |
Which three guarantee that a thread will leave the running state?
|
A. | 1, 2 and 4 |
B. | 2, 5 and 6 |
C. | 3, 4 and 7 |
D. | 4, 5 and 7 |
Answer» C. 3, 4 and 7 | |
123. |
Which two of the following methods are defined in class Thread?
|
A. | 1 and 4 |
B. | 2 and 3 |
C. | 3 and 4 |
D. | 2 and 4 |
Answer» B. 2 and 3 | |
124. |
Which method must be defined by a class implementing the java.lang.Runnable interface? |
A. | void run() |
B. | public void run() |
C. | public void start() |
D. | void run(int priority) |
Answer» C. public void start() | |
125. |
Which of the following will directly stop the execution of a Thread? |
A. | wait() |
B. | notify() |
C. | notifyall() |
D. | exits synchronized code |
Answer» B. notify() | |
126. |
Which will contain the body of the thread? |
A. | run(); |
B. | start(); |
C. | stop(); |
D. | main(); |
Answer» B. start(); | |
127. |
Which method registers a thread in a thread scheduler? |
A. | run(); |
B. | construct(); |
C. | start(); |
D. | register(); |
Answer» D. register(); | |
128. |
Which of the following will not directly cause a thread to stop? |
A. | notify() |
B. | wait() |
C. | InputStream access |
D. | sleep() |
Answer» B. wait() | |
129. |
Which class or interface defines the wait(), notify(),and notifyAll() methods? |
A. | Object |
B. | Thread |
C. | Runnable |
D. | Class |
Answer» B. Thread | |
130. |
which of these will create and start this thread?
|
A. | new Runnable(MyRunnable).start(); |
B. | new Thread(MyRunnable).run(); |
C. | new Thread(new MyRunnable()).start(); |
D. | new MyRunnable().start(); |
Answer» D. new MyRunnable().start(); | |
131. |
What causes compilation to fail?
|
A. | Line 5 |
B. | Line 6 |
C. | Line 12 |
D. | Line 14 |
Answer» E. | |
132. |
What will be the output of the program?
|
A. | bar |
B. | bar done |
C. | foo done |
D. | Compilation fails |
Answer» E. | |
133. |
What will be the output of the program (when you run with the -ea option) ?
|
A. | finished |
B. | Compilation fails. |
C. | An AssertionError is thrown. |
D. | An AssertionError is thrown and finished is output. |
Answer» D. An AssertionError is thrown and finished is output. | |
134. |
Which two cause a compiler error?
|
A. | 2, 4 |
B. | 3, 5 |
C. | 4, 5 |
D. | 1, 2 |
Answer» E. | |
135. |
Given a method in a protected class, what access modifier do you use to restrict access to that method to only the other members of the same class? |
A. | final |
B. | static |
C. | private |
D. | protected |
E. | volatile |
Answer» D. protected | |
136. |
which line is an example of an inappropriate use of assertions?
|
A. | Line 11 |
B. | Line 12 |
C. | Line 14 |
D. | Line 22 |
Answer» E. | |
137. |
Which is a valid declaration within an interface? |
A. | public static short stop = 23; |
B. | protected short stop = 23; |
C. | transient short stop = 23; |
D. | final void madness(short stop); |
Answer» B. protected short stop = 23; | |
138. |
What is the widest valid returnType for methodA in line 3?
|
A. | int |
B. | byte |
C. | long |
D. | double |
Answer» E. | |
139. |
Which is valid in a class that extends class A?
|
A. | public int method1(int a, int b) {return 0; } |
B. | private int method1(int a, int b) { return 0; } |
C. | public short method1(int a, int b) { return 0; } |
D. | static protected int method1(int a, int b) { return 0; } |
Answer» B. private int method1(int a, int b) { return 0; } | |
140. |
Which one creates an instance of an array? |
A. | int[ ] ia = new int[15]; |
B. | float fa = new float[20]; |
C. | char[ ] ca = "Some String"; |
D. | int ia[ ] [ ] = { 4, 5, 6 }, { 1,2,3 }; |
Answer» B. float fa = new float[20]; | |
141. |
What is the most restrictive access modifier that will allow members of one class to have access to members of another class in the same package? |
A. | public |
B. | abstract |
C. | protected |
D. | synchronized |
E. | default access |
Answer» F. | |
142. |
Which two of the following are legal declarations for nonnested classes and interfaces?
|
A. | 1 and 4 |
B. | 2 and 5 |
C. | 3 and 6 |
D. | 4 and 6 |
Answer» D. 4 and 6 | |
143. |
Which of the following class level (nonlocal) variable declarations will not compile? |
A. | protected int a; |
B. | transient int b = 3; |
C. | private synchronized int e; |
D. | volatile int d; |
Answer» D. volatile int d; | |
144. |
Which of the following is/are legal method declarations?
|
A. | 1 and 3 |
B. | 2 and 4 |
C. | 1 only |
D. | All of them are legal declarations. |
Answer» E. | |
145. |
Which cause a compiler error? |
A. | int[ ] scores = {3, 5, 7}; |
B. | int [ ][ ] scores = {2,7,6}, {9,3,45}; |
C. | String cats[ ] = {"Fluffy", "Spot", "Zeus"}; |
D. | boolean results[ ] = new boolean [] {true, false, true}; |
E. | Integer results[ ] = {new Integer(3), new Integer(5), new Integer(8)}; |
Answer» C. String cats[ ] = {"Fluffy", "Spot", "Zeus"}; | |
146. |
What will be the output of the program?
|
A. | x = 0 |
B. | x = 1 |
C. | Compilation fails. |
D. | An exception is thrown at runtime. |
Answer» D. An exception is thrown at runtime. | |
147. |
What will be the output of the program?
|
A. | Class A |
B. | Compilation fails. |
C. | An exception is thrown at line 3. |
D. | The code executes with no output. |
Answer» E. | |
148. |
What will be the output of the program?
|
A. | 0 |
B. | 1 |
C. | 2 |
D. | Compilation fails. |
Answer» E. | |
149. |
What will be the output of the program?
|
A. | 0 |
B. | 1 |
C. | 2 |
D. | Compilation fails. |
Answer» E. | |
150. |
Which statement is true for the class java.util.HashSet? |
A. | The elements in the collection are ordered. |
B. | The collection is guaranteed to be immutable. |
C. | The elements in the collection are guaranteed to be unique. |
D. | The elements in the collection are accessed using a unique key. |
Answer» D. The elements in the collection are accessed using a unique key. | |