Q1. What is the output?
List<Integer> list =
Arrays.asList(1,2,3);
list.forEach(System.out::print);
A. 1 2 3
B. 123
C. [1,2,3]
D. Compilation Error
Q2. What is the output?
Stream.of(1,2,3,4)
.filter(x -> x % 2 == 0)
.forEach(System.out::print);
A. 1234
B. 24
C. 13
D. Exception
Q3. What is the output?
Optional<String> op =
Optional.of(“Java”);
System.out.println(op.get());
A. Optional[Java]
B. Java
C. null
D. Exception
Q4. What happens here?
Optional.empty().get();
A. null
B. NoSuchElementException
C. NullPointerException
D. Compilation Error
Q5. What is the output?
interface Vehicle {
default void start() {
System.out.print(“Vehicle “);
}
}
class Car implements Vehicle {
}
public class Test {
public static void main(String[] args) {
new Car().start();
}
}
A. Car
B. Vehicle
C. Vehicle Car
D. Compilation Error
Q6. What is the output?
class Parent {
static void show() {
System.out.println(“Parent”);
}
}
class Child extends Parent {
static void show() {
System.out.println(“Child”);
}
}
public class Test {
public static void main(String[] args) {
Parent p = new Child();
p.show();
}
}
A. Parent
B. Child
C. Exception
D. Compilation Error
Q7. Insert the missing code.
List<String> names =
Arrays.asList(“Java”,”Spring”);
__________
Desired output:
JAVA
SPRING
A.
names.stream()
.map(String::toUpperCase)
.forEach(System.out::println);
B.
names.toUpperCase();
C.
names.print();
D.
System.out.println(names);
Q8. Exception and inheritance.
class Parent {
void read() throws Exception {
}
}
class Child extends Parent {
void read() throws RuntimeException {
}
}
A. Compilation Error
B. Valid override
C. Runtime Exception
D. Exception
Q9. Time complexity of Merge Sort.
A. O(n²)
B. O(log n)
C. O(n log n)
D. O(n)
Q10. Which interface represents a function that accepts one argument and returns a result?
A. Predicate
B. Consumer
C. Function
D. Supplier
Answers – SET 4
| Q | Answer | Explanation |
| 1 | B | Method reference prints without spaces. |
| 2 | B | Only even numbers pass filter. |
| 3 | B | Optional contains value. |
| 4 | B | No value present. |
| 5 | B | Default method inherited. |
| 6 | A | Static methods are hidden, not overridden. |
| 7 | A | map() converts to uppercase. |
| 8 | B | Unchecked exception allowed. |
| 9 | C | Merge sort complexity. |
| 10 | C | Function<T,R>. |
SET 5 – OCP Challenge Round
Q1. What is the output?
StringBuilder sb =
new StringBuilder(“Java”);
sb.append(“17”);
System.out.println(sb);
A. Java
B. 17
C. Java17
D. Exception
Q2. What is the output?
int x = 10;
System.out.println(++x + x++);
A. 20
B. 21
C. 22
D. 23
Q3. What is the output?
String s =
“Java”;
System.out.println(
s.substring(1,3));
A. av
B. ava
C. va
D. Jav
Q4. What is the output?
Map<String,Integer> map =
new HashMap<>();
map.put(“A”,1);
map.put(“A”,2);
System.out.println(
map.get(“A”));
A. 1
B. 2
C. Exception
D. null
Q5. What is the output?
enum Status {
OPEN,CLOSED
}
public class Test {
public static void main(String[] args) {
System.out.println(
Status.OPEN.ordinal());
}
}
A. 0
B. 1
C. OPEN
D. Exception
Q6. What is the output?
System.out.println(
true && false || true);
A. true
B. false
C. Exception
D. Compilation Error
Q7. Insert missing code.
Predicate<Integer> p =
_________;
System.out.println(
p.test(20));
Desired output:
true
A.
x -> x > 10
B.
x > 10
C.
return x > 10
D.
() -> true
Q8. Exception prediction.
try {
throw new IOException();
}
catch(RuntimeException e) {
System.out.println(“Runtime”);
}
catch(Exception e) {
System.out.println(“Exception”);
}
A. Runtime
B. Exception
C. IOException
D. Compilation Error
Q9. Which algorithm uses Queue internally?
A. DFS
B. BFS
C. Binary Search
D. Merge Sort
Q10. Which collection is thread-safe?
A. ArrayList
B. HashMap
C. ConcurrentHashMap
D. HashSet
Answers – SET 5
| Q | Answer | Explanation |
| 1 | C | StringBuilder is mutable. |
| 2 | C | 11 + 11 = 22. |
| 3 | A | Index 1 to 2. |
| 4 | B | Second put replaces value. |
| 5 | A | First enum constant index. |
| 6 | A | && evaluated before |
| 7 | A | Valid lambda expression. |
| 8 | B | IOException caught by Exception. |
| 9 | B | Breadth-first search uses queue. |
| 10 | C | Thread-safe map implementation. |
Final Evaluation Matrix
| Score | Assessment |
| 45–50 | Outstanding Java Developer |
| 40–44 | Strong Core Java Knowledge |
| 35–39 | Good Fundamentals |
| 30–34 | Average |
| 20–29 | Needs Improvement |
| Below 20 | Requires Core Java Training |
Topics Covered
✅ OOP and Inheritance
✅ Runtime Polymorphism
✅ Method Overriding
✅ Exception Handling
✅ Exception Inheritance Rules
✅ Strings and StringBuilder
✅ Enums
✅ Operators and Evaluation Order
✅ Collections Framework
✅ Java 8 Lambdas
✅ Streams and Optional
✅ Algorithms and Complexity
✅ Missing Code Questions
✅ Output Prediction Questions
Interviewer Recommendations
- Give 30 minutes per set.
- Ask candidates to explain their answers.
- Award bonus points for correct reasoning.
- Ask follow-up questions on incorrect answers.
- Focus on code-reading ability rather than memorization.
Candidates scoring above 40/50 generally demonstrate strong Core Java fundamentals and are typically successful in enterprise Java development roles.