Java MCQ Test Prep Questions
Java MCQ Test Prep Questions
System.out.println(arrList);
}
}
## Q. Which two primitives have wrapper classes that are not merely the name
of the primitive with an uppercase letter?
A. byte and char
B. byte and int
C. char and int
D. None of the above
## Q. How many of the String objects are eligible for garbage collection right
before the end of the main method?
```java
public static void main(String[] fruits) {
String fruit1 = new String("apple");
String fruit2 = new String("orange");
String fruit3 = new String("pear");
fruit3 = fruit1;
fruit2 = fruit3;
fruit1 = fruit2;
}
```
A. None
B. One
C. Two
D. Three
## Q. Which of the following does not compile?
A. double num = 2.718;
B. double num = 2._718;
C. double num = 2.7_1_8;
D. None of the above; they all compile
## Q. What is the value of tip after executing the following code snippet?
```java
int meal = 5;
int tip = 2;
int total = meal + (meal>6 ? ++tip : --tip);
```
A. 1
B. 2
C. 3
D. 6
## Q. What is the output of the following application?
```java
String john = "john";
String jon = new String(john);