



























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
ORACLE CERTIFIED PROFESSIONAL JAVA PROGRAMMER EXAMINATION PRACTICE EXAM QUESTIONS AND CORRECT ANSWERS (VERIFIED ANSWERS) PLUS RATIONALES 2026 Q&A | INSTANT DOWNLOAD PDF
Typology: Exams
1 / 35
This page cannot be seen from the preview
Don't miss anything!




























Question 1 What is the size of an int in Java? A. 8 bits B. 16 bits C. 32 bits D. 64 bits Correct Answer: C. 32 bits Rationale: In Java, the int data type is a 32-bit signed two’s complement integer. This is fixed across all platforms, ensuring portability. Unlike primitive sizes in some languages, Java defines strict sizes for consistency. Question 2 Which keyword is used to inherit a class in Java? A. implements B. extends C. inherits D. super
Correct Answer: B. extends Rationale: The extends keyword is used when one class inherits from another class. It allows the subclass to reuse methods and fields of the parent class, supporting code reuse and polymorphism. Question 3 Which of these is NOT a Java access modifier? A. public B. private C. protected D. friendly Correct Answer: D. friendly Rationale: Java does not define a friendly access modifier. The default access level (no keyword) is sometimes informally called "package-private," but it is not named friendly in Java syntax. Question 4 What is the default value of a boolean variable in Java? A. true B. false C. null D. 0 Correct Answer: B. false Rationale: Instance variables of type boolean default to false if not explicitly initialized. Local variables, however, must be explicitly initialized before use. Question 5
Question 8 Which collection does NOT allow duplicates? A. List B. Set C. Queue D. ArrayList Correct Answer: B. Set Rationale: A Set collection in Java automatically disallows duplicate elements, ensuring uniqueness of stored items. Question 9 Which keyword prevents method overriding? A. static B. final C. private D. abstract Correct Answer: B. final Rationale: The final keyword prevents a method from being overridden in a subclass, ensuring its implementation remains unchanged. Question 10 What is method overloading? A. Same method name, different parameters B. Same method name, same parameters C. Different method names D. Inheritance of methods
Correct Answer: A. Same method name, different parameters Rationale: Method overloading allows multiple methods with the same name but different parameter lists, enabling compile-time polymorphism. Question 11 Which package contains Scanner class? A. java.io B. java.util C. java.lang D. java.net Correct Answer: B. java.util Rationale: The Scanner class is part of java.util package and is used for input parsing from various sources like keyboard or files. Question 12 What is autoboxing? A. Converting object to primitive B. Converting primitive to object C. Converting string to integer D. Converting array to list Correct Answer: B. Converting primitive to object Rationale: Autoboxing is the automatic conversion of primitive types into their corresponding wrapper classes, such as int to Integer. Question 13 Which operator is used for comparison? A. = B. ==
Which loop is guaranteed to execute at least once? A. for B. while C. do-while D. foreach Correct Answer: C. do-while Rationale: A do-while loop executes the body first before checking the condition, ensuring at least one execution. Question 17 Which keyword refers to current object? A. this B. super C. self D. current Correct Answer: A. this Rationale: The this keyword refers to the current instance of the class and is used to differentiate instance variables from parameters. Question 18 Which is not a primitive type? A. int B. float C. String D. char Correct Answer: C. String Rationale: String is a reference type in Java, not a primitive data type.
Question 19 Which collection is synchronized? A. ArrayList B. HashMap C. Vector D. LinkedList Correct Answer: C. Vector Rationale: Vector is synchronized, making it thread-safe, unlike most modern collections which are not synchronized by default. Question 20 Which keyword handles exceptions? A. throw B. throws C. try D. catch Correct Answer: D. catch Rationale: The catch block is used to handle exceptions that occur in the try block. Question 21 What is polymorphism? A. Multiple classes B. Multiple forms of a method C. Single inheritance D. Data hiding
C. execute() D. init() Correct Answer: B. start() Rationale: The start() method creates a new thread and internally calls the run() method. Question 25 Which keyword defines constant? A. const B. final C. static D. define Correct Answer: B. final Rationale: The final keyword is used to declare constants in Java whose values cannot be changed. Question 26 Which of these is part of OOP? A. Compilation B. Inheritance C. Execution D. Memory allocation Correct Answer: B. Inheritance Rationale: Inheritance is one of the four pillars of OOP, along with encapsulation, polymorphism, and abstraction. Question 27
Which method converts string to int? A. parseInt() B. toInt() C. valueOf() only D. convert() Correct Answer: A. parseInt() Rationale: Integer.parseInt() converts a String into an integer primitive type. Question 28 Which class is root of all classes? A. Object B. Class C. Base D. Root Correct Answer: A. Object Rationale: All Java classes inherit from java.lang.Object either directly or indirectly. Question 29 Which keyword is used for package creation? A. package B. import C. class D. module Correct Answer: A. package Rationale: The package keyword is used to define a namespace for classes. Question 30
Which is runtime exception? A. IOException B. SQLException C. NullPointerException D. FileNotFoundException Correct Answer: C. NullPointerException Rationale: Runtime exceptions occur during execution and are unchecked, like NullPointerException. Question 34 Which is interface keyword? A. interface B. implements C. extends D. inherit Correct Answer: A. interface Rationale: The interface keyword defines a contract that implementing classes must follow. Question 35 Which method is used to compare strings? A. == B. equals() C. compare() D. match() Correct Answer: B. equals() Rationale: equals() compares actual string content, unlike == which compares references.
Question 36 Which class is used for file handling? A. File B. Path C. Stream D. Buffer Correct Answer: A. File Rationale: The File class represents file and directory pathnames in Java. Question 37 Which keyword is used for inheritance of interface? A. extends B. implements C. inherits D. uses Correct Answer: A. extends Rationale: Interfaces extend other interfaces using extends. Classes implement interfaces using implements. Question 38 Which is wrapper class? A. int B. Integer C. float D. double Correct Answer: B. Integer Rationale: Wrapper classes convert primitives into objects, like Integer for int.
Question 42 Which is collection framework root interface? A. Map B. List C. Collection D. Set Correct Answer: C. Collection Rationale: Collection is the root interface of most Java collection types. Question 43 Which method is used for garbage collection request? A. finalize() B. gc() C. clean() D. delete() Correct Answer: B. gc() Rationale: System.gc() suggests JVM to run garbage collection, though not guaranteed. Question 44 Which is not keyword? A. static B. void C. main D. class Correct Answer: C. main Rationale: main is a method name, not a reserved keyword.
Question 45 Which operator is logical AND? A. & B. && C. AND D. || Correct Answer: B. && Rationale: && is the short-circuit logical AND operator in Java. Question 46 Which is used for multiline comments? A. // B. /* */ C. # D. -- Correct Answer: B. / / _Rationale: Multiline comments in Java are enclosed within / ... /._ Question 47 Which is default package? A. java.util B. java.lang C. java.io D. java.net Correct Answer: B. java.lang Rationale: java.lang is automatically imported in every Java program.
Question 51 Which feature allows multiple methods with same name but different signatures? A. Overriding B. Overloading C. Inheritance D. Encapsulation Correct Answer: B. Overloading Rationale: Method overloading enables compile-time polymorphism by changing parameter lists. Question 52 Which keyword refers to superclass? A. this B. super C. parent D. base Correct Answer: B. super Rationale: super is used to refer to parent class methods or constructors. Question 53 Which is not part of exception handling? A. try B. catch C. throw D. final Correct Answer: D. final Rationale: final is unrelated to exception handling mechanisms.
Question 54 Which method is used to read input from keyboard? A. next() B. read() C. input() D. scan() Correct Answer: A. next() Rationale: Scanner.next() reads input from the user. Question 55 Which keyword creates thread? A. thread B. Runnable C. new D. start Correct Answer: C. new Rationale: Threads are instantiated using new Thread() before calling start(). Question 56 Which is correct array declaration? A. int a[]; B. int []a; C. Both A and B D. None Correct Answer: C. Both A and B Rationale: Java supports both array declaration styles. Question 57