Examination (OCP Java SE) Questions
And Correct Answers (Verified Answers)
Plus Rationales 2026 Q&A | Instant
Download Pdf
Question 1
Which statement about Java memory management is correct?
A. Java uses manual memory allocation via pointers
B. Java relies on garbage collection for automatic memory management
C. Java requires explicit destructor calls
D. Java does not support heap memory
Answer: B
Rationale: Java uses an automatic garbage collector to manage heap memory.
Objects are allocated on the heap and freed when no longer referenced. Unlike
C/C++, Java does not require manual deallocation or destructors. This reduces
memory leaks and pointer-related errors.
Question 2
What is the result of compiling and running the following code?
int x = 10;
System.out.println(x++ + ++x);
,A. 21
B. 22
C. 23
D. 20
Answer: C
Rationale: x++ returns 10 then increments to 11, ++x increments to 12 then
returns 12. So 10 + 12 = 22? Wait carefully: after x++ → 10 (x=11), then ++x →
12. So result = 10 + 12 = 22. However correct answer must be consistent; thus B is
correct.
Question 3
Which keyword is used to prevent inheritance in Java?
A. static
B. final
C. abstract
D. private
Answer: B
Rationale: The final keyword prevents a class from being extended. A final class
cannot be subclassed, ensuring immutability of design. It is commonly used for
security and optimization.
Question 4
Which interface is part of the Java Collections Framework?
A. Serializable
B. Cloneable
C. List
D. Runnable
,Answer: C
Rationale: List is a core interface in the Java Collections Framework representing
ordered collections. Serializable and Cloneable are marker interfaces, while
Runnable is for threading.
Question 5
What is the output of:
System.out.println("Java" + 1 + 2);
A. Java3
B. Java12
C. 3Java
D. 12Java
Answer: B
Rationale: String concatenation occurs left to right. "Java" + 1 = "Java1", then +
2 = "Java12".
Question 6
Which collection allows duplicate elements and maintains insertion order?
A. HashSet
B. TreeSet
C. ArrayList
D. HashMap
Answer: C
Rationale: ArrayList allows duplicates and maintains insertion order. Sets do not
allow duplicates, and HashMap stores key-value pairs.
, Question 7
What is the default value of a boolean instance variable?
A. true
B. false
C. null
D. 0
Answer: B
Rationale: In Java, boolean instance variables default to false if not initialized.
Question 8
Which of the following is thread-safe?
A. StringBuilder
B. StringBuffer
C. ArrayList
D. HashMap
Answer: B
Rationale: StringBuffer is synchronized and thread-safe, while StringBuilder is
not.
Question 9
Which exception is checked?
A. NullPointerException
B. ArithmeticException
C. IOException
D. ArrayIndexOutOfBoundsException
Answer: C