You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
####Q. Which of the following declarations does not compile?
217
+
## Q. Which of the following declarations does not compile?
218
218
A. double num1, int num2 = 0;
219
219
B. int num1, num2;
220
220
C. int num1, num2 = 0;
@@ -224,7 +224,7 @@ A. double num1, int num2 = 0;
224
224
```
225
225
**Explanation**: A. Option A does not compile because Java does not allow declaring different types as part of the same declaration.
226
226
227
-
####Q. What is the output of the following?
227
+
## Q. What is the output of the following?
228
228
```java
229
229
publicstaticvoid main(String... args) {
230
230
String chair, table ="metal";
@@ -245,15 +245,15 @@ D. The code does not compile
245
245
<b><a href="#">↥ back to top</a></b>
246
246
</div>
247
247
248
-
####Q. Which is correct about an instance variable of type String?
248
+
## Q. Which is correct about an instance variable of type String?
249
249
A. It defaults to an empty string.
250
250
B. It defaults to null.
251
251
C. It does not have a default value.
252
252
D. It will not compile without initializing on the declaration line
253
253
```
254
254
B. It defaults to null.
255
255
```
256
-
####Q. How many of the following methods compile?
256
+
## Q. How many of the following methods compile?
257
257
```java
258
258
publicclassTest
259
259
{
@@ -282,15 +282,15 @@ C. Two
282
282
```
283
283
**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.
284
284
285
-
####Q. Which of the following does not compile?
285
+
## Q. Which of the following does not compile?
286
286
A. int num = 999;
287
287
B. int num = 9_9_9;
288
288
C. int num = _9_99;
289
289
D. None of the above; they all compile.
290
290
```
291
291
C. int num = _9_99;
292
292
```
293
-
####Q. Which is the first line to trigger a compiler error?
293
+
## Q. Which is the first line to trigger a compiler error?
294
294
```java
295
295
double d1 =5f; // p1
296
296
double d2 =5.0; // p2
@@ -309,7 +309,7 @@ D. P4
309
309
<b><a href="#">↥ back to top</a></b>
310
310
</div>
311
311
312
-
####Q. How many instance initializers are in this code?
312
+
## Q. How many instance initializers are in this code?
313
313
```java
314
314
publicclassBowling {
315
315
{
@@ -333,7 +333,7 @@ D. Three
333
333
```
334
334
C. Two
335
335
```
336
-
####Q. What is true of the finalize() method?
336
+
## Q. What is true of the finalize() method?
337
337
A. It may be called zero or one times.
338
338
B. It may be called zero or more times.
339
339
C. It will be called exactly once.
@@ -343,15 +343,15 @@ A. It may be called zero or one times.
343
343
```
344
344
**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.
345
345
346
-
####Q. Which of the following is true about primitives?
346
+
## Q. Which of the following is true about primitives?
347
347
A. You can call methods on a primitive.
348
348
B. You can convert a primitive to a wrapper class object simply by assigning it.
349
349
C. You can convert a wrapper class object to a primitive by calling valueOf().
350
350
D. You can store a primitive directly into an ArrayList.
351
351
```
352
352
B. You can convert a primitive to a wrapper class object simply by assigning it.
353
353
```
354
-
####Q. What is the output of the following?
354
+
## Q. What is the output of the following?
355
355
```java
356
356
Integer integer =newInteger(4);
357
357
System.out.print(integer.byteValue());
@@ -370,7 +370,7 @@ C. The code does not compile.
370
370
<b><a href="#">↥ back to top</a></b>
371
371
</div>
372
372
373
-
####Q. Which two primitives have wrapper classes that are not merely the name of the primitive with an uppercase letter?
373
+
## Q. Which two primitives have wrapper classes that are not merely the name of the primitive with an uppercase letter?
374
374
A. byte and char
375
375
B. byte and int
376
376
C. char and int
@@ -380,7 +380,7 @@ C. char and int
380
380
```
381
381
**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.
382
382
383
-
####Q. How do you force garbage collection to occur at a certain point?
383
+
## Q. How do you force garbage collection to occur at a certain point?
384
384
A. Call System.forceGc()
385
385
B. Call System.gc()
386
386
C. Call System.requireGc()
@@ -390,7 +390,7 @@ D. None of the above
390
390
```
391
391
**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.
392
392
393
-
####Q. How many of the String objects are eligible for garbage collection right before the end of the main method?
393
+
## Q. How many of the String objects are eligible for garbage collection right before the end of the main method?
394
394
```java
395
395
publicstaticvoid main(String[] fruits) {
396
396
String fruit1 =newString("apple");
@@ -410,7 +410,7 @@ C. Two
410
410
```
411
411
**Explanation**: All three references point to the String apple. This makes the other two String objects eligible for garbage collection.
412
412
413
-
####Q. Which of the following does not compile?
413
+
## Q. Which of the following does not compile?
414
414
A. double num = 2.718;
415
415
B. double num = 2._718;
416
416
C. double num = 2.7_1_8;
@@ -423,7 +423,7 @@ B. double num = 2._718;
423
423
<b><a href="#">↥ back to top</a></b>
424
424
</div>
425
425
426
-
####Q. Which of the following is the output of this code, assuming it runs to completion?
426
+
## Q. Which of the following is the output of this code, assuming it runs to completion?
427
427
```java
428
428
publicclassToy {
429
429
publicvoidplay() {
@@ -450,7 +450,7 @@ B. play-play-
450
450
```
451
451
**Explanation**: If there was a finalize() method, this would be a different story. However, the method here is finalizer. Tricky! That’s just a normal method that doesn’t get called automatically. Therefore clean is never output.
452
452
453
-
####Q. What is the value of tip after executing the following code snippet?
453
+
## Q. What is the value of tip after executing the following code snippet?
454
454
```java
455
455
int meal =5;
456
456
int tip =2;
@@ -465,7 +465,7 @@ A. 1
465
465
```
466
466
**Explanation**: In ternary expressions, only one of the two right-most expressions are evaluated. Since `meal>6` is false, `––tip` is evaluated and `++tip` is skipped. The result is that `tip` is changed from 2 to 1.
467
467
468
-
####Q. What is the output of the following application?
468
+
## Q. What is the output of the following application?
0 commit comments