Java Certification Exam Questions and Answers (OCPJP), Exams of Java Programming

A set of questions and answers related to the java certification exam (oracle certified professional java programmer - ocpjp). It includes verified answers and rationales for each question, making it a useful resource for exam preparation. The questions cover various java concepts, including inheritance, data types, methods, operators, and exception handling. This q&a is designed to help students and professionals test their knowledge and understanding of java programming concepts. It serves as a valuable tool for self-assessment and exam readiness.

Typology: Exams

2025/2026

Available from 12/22/2025

masterystudyhub
masterystudyhub 🇺🇸

4.7

(3)

4.4K documents

1 / 26

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
JAVA CERTIFICATION EXAM (ORACLE
CERTIFIED PROFESSIONAL JAVA
PROGRAMMER – OCPJP) QUESTION
AND CORRECT ANSWERS (VERIFIED
ANSWERS) PLUS RATIONALES 2026 Q&A
INSTANT DOWNLOAD PDF
1. Which keyword is used to inherit a class in Java?
A. implements
B. inherits
C. extends
D. super
Answer: C
Rationale: In Java, the extends keyword is used by a subclass to inherit
another class.
2. Which data type is used to create a variable that should store text?
A. char
B. String
C. string
D. Text
Answer: B
Rationale: String is a predefined class in Java used to store sequences of
characters.
3. What is the size of an int data type in Java?
A. 8 bits
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a

Partial preview of the text

Download Java Certification Exam Questions and Answers (OCPJP) and more Exams Java Programming in PDF only on Docsity!

JAVA CERTIFICATION EXAM (ORACLE

CERTIFIED PROFESSIONAL JAVA

PROGRAMMER – OCPJP) QUESTION

AND CORRECT ANSWERS (VERIFIED

ANSWERS) PLUS RATIONALES 2026 Q&A

INSTANT DOWNLOAD PDF

  1. Which keyword is used to inherit a class in Java? A. implements B. inherits C. extends D. super Answer: C Rationale: In Java, the extends keyword is used by a subclass to inherit another class.
  2. Which data type is used to create a variable that should store text? A. char B. String C. string D. Text Answer: B Rationale: String is a predefined class in Java used to store sequences of characters.
  3. What is the size of an int data type in Java? A. 8 bits

B. 16 bits C. 32 bits D. 64 bits Answer: C Rationale: An int in Java is always 32 bits regardless of platform.

  1. Which method is the entry point of a Java program? A. start() B. run() C. main() D. init() Answer: C Rationale: The JVM starts execution from the public static void main(String[] args) method.
  2. Which access modifier makes a member visible only within the same class? A. public B. protected C. default D. private Answer: D Rationale: private members are accessible only within the declaring class.
  3. Which operator is used to compare two values for equality? A. = B. == C. equals D. != Answer: B Rationale: The == operator compares primitive values and object references for equality.
  4. Which of the following is NOT a Java primitive type? A. int B. boolean

11.What is method overloading? A. Same method name with different return types only B. Same method name with different parameter lists C. Different method names with same parameters D. Same method name in different classes only Answer: B Rationale: Method overloading requires the same method name but different parameter lists. 12.Which keyword is used to call a superclass constructor? A. this B. super C. parent D. base Answer: B Rationale: super() is used to invoke the constructor of the parent class. 13.Which exception is thrown when dividing by zero? A. NullPointerException B. ArithmeticException C. IOException D. NumberFormatException Answer: B Rationale: Division by zero for integers results in an ArithmeticException. 14.Which interface provides capability to store objects in sequence? A. Map B. Set C. List D. Queue Answer: C Rationale: The List interface maintains ordered collections with duplicate elements allowed.

15.Which collection does not allow duplicate elements? A. ArrayList B. LinkedList C. HashSet D. Vector Answer: C Rationale: A Set implementation like HashSet does not allow duplicates. 16.What does JVM stand for? A. Java Variable Machine B. Java Virtual Machine C. Java Verified Machine D. Java Visual Machine Answer: B Rationale: JVM executes Java bytecode and provides platform independence. 17.Which keyword is used to handle exceptions? A. try B. catch C. throw D. All of the above Answer: D Rationale: Java exception handling uses try, catch, and throw. 18.Which class is the superclass of all Java classes? A. System B. Object C. Class D. Runtime Answer: B Rationale: Every Java class implicitly extends java.lang.Object. 19.Which keyword is used to create an object? A. new

23.Which of the following is immutable? A. StringBuilder B. StringBuffer C. String D. ArrayList Answer: C Rationale: String objects cannot be modified after creation. 24.Which modifier makes a method belong to the class rather than objects? A. final B. static C. abstract D. synchronized Answer: B Rationale: static methods belong to the class, not instances. 25.What is encapsulation? A. Hiding implementation details B. Inheriting properties C. Overloading methods D. Compiling code Answer: A Rationale: Encapsulation bundles data and methods and restricts direct access. 26.Which Java feature supports runtime method binding? A. Abstraction B. Encapsulation C. Inheritance D. Dynamic binding Answer: D Rationale: Dynamic binding resolves method calls at runtime.

27.Which keyword is used to define a constant? A. static B. final C. const D. define Answer: B Rationale: final prevents modification of variables once assigned. 28.Which statement is true about abstract classes? A. They cannot have constructors B. They cannot have implemented methods C. They cannot be instantiated D. They must be final Answer: C Rationale: Abstract classes cannot be instantiated directly. 29.Which interface is used to sort collections? A. Comparator B. Serializable C. Cloneable D. Runnable Answer: A Rationale: Comparator defines custom sorting logic. 30.Which stream is used for reading byte data? A. Reader B. Writer C. InputStream D. OutputStream Answer: C Rationale: InputStream handles byte-based input operations.

C. synchronized D. volatile Answer: C Rationale: synchronized ensures thread-safe access to shared resources. 36.Which class is used to create threads? A. Thread B. Runnable C. Executor D. Callable Answer: A Rationale: The Thread class represents a thread of execution. 37.Which annotation is used to override a method? A. @Overload B. @Override C. @Inherited D. @Suppress Answer: B Rationale: @Override ensures a method correctly overrides a superclass method. 38.Which Java feature allows multiple methods with same name? A. Inheritance B. Polymorphism C. Overloading D. Overriding Answer: C Rationale: Method overloading allows same method name with different parameters. 39.Which statement about constructors is true? A. They have return types

B. They must be static C. They initialize objects D. They can be abstract Answer: C Rationale: Constructors initialize new objects. 40.Which keyword refers to current object? A. this B. super C. self D. object Answer: A Rationale: this refers to the current instance. 41.Which type of inheritance is NOT supported by Java classes? A. Single B. Multilevel C. Multiple D. Hierarchical Answer: C Rationale: Java does not support multiple inheritance with classes. 42.Which interface enables object cloning? A. Serializable B. Cloneable C. Comparable D. Runnable Answer: B Rationale: Cloneable allows objects to be cloned. 43.Which class is used to read text from console? A. Scanner B. Console

D. super Answer: B Rationale: Interfaces extend other interfaces using extends. 48.Which class cannot be subclassed? A. Abstract class B. Public class C. Final class D. Protected class Answer: C Rationale: final classes cannot be extended. 49.Which feature improves performance by avoiding recompilation? A. JVM B. JIT Compiler C. Garbage Collector D. Class Loader Answer: B Rationale: JIT compiles bytecode into native code at runtime. 50.Which memory area stores objects? A. Stack B. Heap C. Method Area D. Register Answer: B Rationale: Objects are stored in heap memory. 51.Which Java statement exits a loop? A. continue B. break C. exit D. stop

Answer: B Rationale: break terminates loop execution. 52.Which keyword is used to inherit interfaces? A. implements B. extends C. super D. this Answer: B Rationale: Interfaces inherit other interfaces using extends. 53.Which collection is synchronized by default? A. ArrayList B. HashMap C. Vector D. HashSet Answer: C Rationale: Vector methods are synchronized by default. 54.Which package contains ArrayList? A. java.io B. java.lang C. java.util D. java.net Answer: C Rationale: ArrayList is part of java.util. 55.Which keyword is used to declare a package? A. import B. include C. package D. namespace Answer: C Rationale: The package keyword groups related classes.

60.Which method compares object content? A. == B. equals() C. compare() D. match() Answer: B Rationale: equals() compares logical equality of objects. 61.Which class is thread-safe? A. StringBuilder B. StringBuffer C. ArrayList D. HashMap Answer: B Rationale: StringBuffer methods are synchronized. 62.Which Java type stores true or false? A. int B. boolean C. Boolean D. char Answer: B Rationale: boolean is the primitive type for true/false values. 63.Which operator increments value by one? A. + B. ++ C. += D. inc Answer: B Rationale: ++ increases value by one.

64.Which keyword is used to define abstract method? A. final B. static C. abstract D. native Answer: C Rationale: abstract declares a method without implementation. 65.Which Java feature allows code reuse? A. Polymorphism B. Inheritance C. Abstraction D. Encapsulation Answer: B Rationale: Inheritance enables reuse of existing code. 66.Which class loads classes into memory? A. JVM B. JRE C. ClassLoader D. Compiler Answer: C Rationale: ClassLoader loads class bytecode at runtime. 67.Which operator checks logical AND? A. & B. && C. AND D. | Answer: B Rationale: && performs short-circuit logical AND.

72.Which method starts a thread? A. run() B. execute() C. start() D. init() Answer: C Rationale: start() begins thread execution. 73.Which Java feature supports platform independence? A. Bytecode B. Compiler C. JIT D. Garbage Collector Answer: A Rationale: Bytecode runs on any JVM regardless of OS. 74.Which keyword is used to handle multiple exceptions? A. multi-catch B. throws C. catch D. try Answer: C Rationale: Multiple catch blocks handle different exceptions. 75.Which collection is best for fast lookup? A. ArrayList B. LinkedList C. HashMap D. Vector Answer: C Rationale: HashMap provides fast key-based access.

76.Which exception occurs when class is not found? A. IOException B. ClassNotFoundException C. SQLException D. RuntimeException Answer: B Rationale: ClassNotFoundException occurs when class loading fails. 77.Which keyword ensures a variable value is read from main memory? A. static B. final C. volatile D. synchronized Answer: C Rationale: volatile ensures visibility across threads. 78.Which method converts string to integer? A. Integer.valueOf() B. parseInt() C. toInt() D. convert() Answer: B Rationale: Integer.parseInt() converts String to int. 79.Which block encloses risky code? A. try B. catch C. finally D. throw Answer: A Rationale: Code that may throw exceptions is placed in try. 80.Which Java version introduced lambda expressions? A. Java 5 B. Java 6