Skip to content

Commit b24bbc4

Browse files
committed
Update java-multiple-choice-questions-answers.md
1 parent 3203202 commit b24bbc4

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

java-multiple-choice-questions-answers.md

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,9 @@ C. int num1, num2 = 0;
209209
D. int num1 = 0, num2 = 0;
210210
```
211211
A. double num1, int num2 = 0;
212-
213-
Explanation: A. Option A does not compile because Java does not allow declaring different types as
214-
part of the same declaration.
215212
```
213+
**Explanation**: A. Option A does not compile because Java does not allow declaring different types as part of the same declaration.
214+
216215
#### Q. What is the output of the following?
217216
public static void main(String... args) {
218217
String chair, table = "metal";
@@ -225,9 +224,9 @@ C. nullmetal
225224
D. The code does not compile
226225
```
227226
D. The code does not compile
228-
229-
Explanation: The local variable chair may not have been initialized
230227
```
228+
**Explanation**: The local variable chair may not have been initialized
229+
231230
#### Q. Which is correct about an instance variable of type String?
232231
A. It defaults to an empty string.
233232
B. It defaults to null.
@@ -262,11 +261,9 @@ C. Two
262261
D. Three
263262
```
264263
C. Two
265-
266-
Explanation: Objects have instance methods while primitives do not. Since int is a primitive, you
267-
cannot call instance methods on it. Integer and String are both objects and have
268-
instance methods
269264
```
265+
**Explanation**: Objects have instance methods while primitives do not. Since int is a primitive, you cannot call instance methods on it. Integer and String are both objects and have instance methods.
266+
270267
#### Q. Which of the following does not compile?
271268
A. int num = 999;
272269
B. int num = 9_9_9;
@@ -288,9 +285,9 @@ C. p3
288285
D. p4
289286
```
290287
D. P4
291-
292-
Explanation: Type mismatch: cannot convert from double to float
293288
```
289+
**Explanation**: Type mismatch: cannot convert from double to float
290+
294291
#### Q. How many instance initializers are in this code?
295292
```java
296293
public class Bowling {
@@ -322,10 +319,9 @@ C. It will be called exactly once.
322319
D. It may be called one or more times.
323320
```
324321
A. It may be called zero or one times.
325-
326-
The finalize() method may not be called, such as if your program crashes.
327-
However, it is guaranteed to be called no more than once.
328322
```
323+
**Explanation**: The `finalize()` method may not be called, such as if your program crashes. However, it is guaranteed to be called no more than once.
324+
329325
#### Q. Which of the following is true about primitives?
330326
A. You can call methods on a primitive.
331327
B. You can convert a primitive to a wrapper class object simply by assigning it.
@@ -356,19 +352,19 @@ C. char and int
356352
D. None of the above
357353
```
358354
C. char and int
359-
360-
Explanation: The wrapper class for int is Integer and the wrapper class for char is Character. All other primitives have the same name. For example, the wrapper class for boolean is Boolean.
361355
```
356+
**Explanation**: The wrapper class for int is Integer and the wrapper class for char is Character. All other primitives have the same name. For example, the wrapper class for boolean is Boolean.
357+
362358
#### Q. How do you force garbage collection to occur at a certain point?
363359
A. Call System.forceGc()
364360
B. Call System.gc()
365361
C. Call System.requireGc()
366362
D. None of the above
367363
```
368364
D. None of the above
369-
370-
Explanation: While you can suggest to the JVM that it might want to run a garbage collection cycle, the JVM is free to ignore your suggestion.
371365
```
366+
**Explanation**: While you can suggest to the JVM that it might want to run a garbage collection cycle, the JVM is free to ignore your suggestion.
367+
372368
#### Q. How many of the String objects are eligible for garbage collection right before the end of the main method?
373369
```java
374370
public static void main(String[] fruits) {
@@ -386,9 +382,9 @@ C. Two
386382
D. Three
387383
```
388384
C. Two
389-
390-
Explanation: All three references point to the String apple. This makes the other two String objects eligible for garbage collection.
391385
```
386+
**Explanation**: All three references point to the String apple. This makes the other two String objects eligible for garbage collection.
387+
392388
#### Q. Which of the following does not compile?
393389
A. double num = 2.718;
394390
B. double num = 2._718;

0 commit comments

Comments
 (0)