Preparing for technical interviews requires a deep understanding of object-oriented programming paradigms, memory management, runtime behavior, and modern language enhancements. Java technical assessments typically probe foundational components such as the Java Virtual Machine (JVM), exception lifecycles, concurrency models, and the internal mechanics of data structures like HashMaps. Mastering these concepts ensures developers can write secure, scalable, and high-performance enterprise applications while confidently navigating rigorous technical evaluations.
Java Interview Questions MCQs
1 min read
Correct Answer: b) Java Virtual Machine (JVM)
Explanation:
The JVM is the engine that drives the Java code. It converts Java bytecode into machine-specific instructions.
Correct Answer: c) JDK contains JRE and development tools, while JRE provides the environment to run Java applications
Explanation:
The JDK is a full-featured software development kit for Java, including the JRE, compilers, and tools.
Correct Answer: c) So that the JVM can invoke it without instantiating the class
Explanation:
The JVM needs to call the main method before any objects are created. Declaring it static allows it to be invoked on the class itself.
Correct Answer: d) private
Explanation:
A top-level class cannot be private or protected. Only nested inner classes can have these access modifiers.
Correct Answer: b) Its value cannot be modified once initialized
Explanation:
A final variable acts as a constant in Java. Once a value is assigned, it cannot be reassigned.
Correct Answer: b) int
Explanation:
The hashCode() method returns an integer representation of the object memory address or value, used in hashing data structures.
Correct Answer: b) To save memory space in the String pool and provide thread safety
Explanation:
Immutability allows Java to cache String literals securely in the String pool, improving memory efficiency.
Correct Answer: a) StringBuffer is synchronized, while StringBuilder is not
Explanation:
StringBuffer is thread-safe due to synchronized methods, making it slower than StringBuilder, which is not synchronized.
Correct Answer: d) The operator compares memory addresses, while the method compares logical equivalence
Explanation:
The double equals operator checks for reference equality, while the equals() method checks for value equality.
Correct Answer: d) They can have both abstract and concrete methods
Explanation:
Abstract classes cannot be instantiated, but they can have constructors and a mix of abstract and non-abstract methods.
Correct Answer: b) Yes, through interfaces
Explanation:
Java avoids the Diamond Problem by not allowing multiple inheritance of classes, but a class can implement multiple interfaces.
Correct Answer: c) To refer to the immediate parent class object
Explanation:
The super keyword is a reference variable used to refer to immediate parent class objects, methods, or constructors.
Correct Answer: a) Defining multiple methods with the same name but different parameters in the same class
Explanation:
Method overloading is a compile-time polymorphism where methods have the same name but differ in type or number of arguments.
Correct Answer: b) Providing a specific implementation in a subclass for a method defined in its superclass
Explanation:
Method overriding is runtime polymorphism where a subclass provides its own implementation for an inherited method.
Correct Answer: b) To check if an object is an instance of a specific class or interface
Explanation:
The instanceof operator returns a boolean value indicating whether an object is of a particular class or interface type.
Correct Answer: c) Encapsulation
Explanation:
Encapsulation is the mechanism of wrapping the data and code acting on the data together, hiding internal state.
Correct Answer: b) Casting a subclass reference to a superclass type
Explanation:
Upcasting is assigning a child class object to a parent class reference variable. It is done implicitly in Java.
Correct Answer: a) Casting a superclass reference to a subclass type
Explanation:
Downcasting is explicitly casting a parent class reference back to a child class type.
Correct Answer: c) IOException
Explanation:
Checked exceptions are checked at compile-time. IOException is checked, while the others are unchecked runtime exceptions.
Correct Answer: c) Throwable
Explanation:
The Throwable class is the superclass of all errors and exceptions in the Java language.
Correct Answer: b) It is valid, and the finally block executes whether an exception occurs or not
Explanation:
A try block can be followed by a finally block without a catch block. The finally block always executes.
Correct Answer: c) throw is used to explicitly throw an exception, throws is used in the method signature to declare exceptions
Explanation:
throw is followed by an instance of an exception, whereas throws is followed by exception class names in the method declaration.
Correct Answer: d) Iterable
Explanation:
The Iterable interface is the root interface for all collection classes. Collection extends Iterable.
Correct Answer: c) Map
Explanation:
The Map interface represents a mapping between a key and a value. It does not extend the Collection interface.
Correct Answer: b) ArrayList uses a dynamic array; LinkedList uses a doubly linked list
Explanation:
ArrayList provides fast random access, while LinkedList provides faster insertions and deletions.
Correct Answer: c) LinkedHashSet
Explanation:
LinkedHashSet uses a hash table and a doubly-linked list to maintain the insertion order of its elements.
Correct Answer: c) HashMap allows one null key and multiple null values, Hashtable does not allow nulls
Explanation:
HashMap is non-synchronized and permits nulls. Hashtable is a legacy class that is synchronized and strictly non-null.
Correct Answer: c) It throws ConcurrentModificationException if the collection is structurally modified during iteration
Explanation:
Fail-fast iterators immediately throw an exception to prevent non-deterministic behavior during concurrent modification.
Correct Answer: b) ListIterator
Explanation:
ListIterator extends Iterator and provides methods to traverse the list in both forward and backward directions.
Correct Answer: a) Comparable provides natural sorting, Comparator provides custom sorting
Explanation:
Comparable modifies the class itself (compareTo) for natural order. Comparator is external (compare) for custom strategies.
Correct Answer: a) By extending the Thread class or implementing the Runnable interface
Explanation:
Java provides two main ways to create a thread: extending the java.lang.Thread class or implementing java.lang.Runnable.
Correct Answer: c) The code inside run() executes in the current thread instead of a new thread
Explanation:
Calling run() does not create a new thread call stack. It executes sequentially in the current thread.
Correct Answer: c) wait()
Explanation:
The wait() method causes the current thread to wait and releases the lock it holds on the object.
Correct Answer: c) When two or more threads are blocked forever, waiting for each other to release a lock
Explanation:
Deadlock is a concurrency failure mode where threads wait indefinitely for locks held by one another.
Correct Answer: b) To ensure visibility of a variable updates across different threads
Explanation:
The volatile keyword ensures that reads and writes to a variable go directly to main memory, preventing thread caching issues.
Correct Answer: d) It returns a result and can throw checked exceptions
Explanation:
Unlike Runnable, Callable's call() method can return a value (wrapped in a Future) and throw checked exceptions.
Correct Answer: b) To manage a pool of threads and abstract thread execution
Explanation:
ExecutorService provides a higher-level framework for managing and pooling threads, simplifying concurrent task execution.
Correct Answer: c) The Garbage Collector
Explanation:
The finalize() method is called by the Garbage Collector just before reclaiming the object's memory.
Correct Answer: b) It sends a request to the JVM to run the Garbage Collector
Explanation:
System.gc() is only a hint to the JVM. The JVM ultimately decides when to perform garbage collection.
Correct Answer: c) An interface with no methods or constants, used to signal a property to the JVM
Explanation:
Marker interfaces like Serializable contain no methods and instruct the JVM to treat the implementing class in a special way.
Correct Answer: b) To prevent a variable from being serialized
Explanation:
When an object is serialized, any field marked as transient is ignored and will not be saved.
Correct Answer: b) The process where the compiler removes generic type information to ensure backward compatibility
Explanation:
Type erasure removes generic type bounds at compile time, replacing them with Object or bounds.
Correct Answer: b) Any object type (unknown type)
Explanation:
The question mark represents an unknown type in generic programming, often used as bounded wildcards.
Correct Answer: b) java.lang.Enum
Explanation:
Every enum type implicitly extends java.lang.Enum, meaning enums cannot extend other classes.
Correct Answer: b) A tag providing metadata about the program that is not part of the program itself
Explanation:
Annotations provide data about a program to the compiler, deployment tools, or runtime environments.
Correct Answer: b) An interface with exactly one abstract method
Explanation:
Functional interfaces have a single abstract method and can be implemented using lambda expressions.
Correct Answer: b) An anonymous function that can be created without belonging to any class
Explanation:
Lambda expressions provide a clear and concise way to represent one-method interfaces using an expression.
Correct Answer: c) @FunctionalInterface
Explanation:
The @FunctionalInterface annotation informs the compiler to check that the interface contains exactly one abstract method.
Correct Answer: b) To process collections of objects in a functional and declarative style
Explanation:
Streams provide a high-level abstraction for processing sequences of data using operations like map, filter, and reduce.
Correct Answer: c) collect()
Explanation:
collect() is a terminal operation that triggers the execution of the stream pipeline and returns a result.
Correct Answer: a) map() transforms values, flatMap() transforms and flattens nested streams
Explanation:
map() applies a function to each element. flatMap() applies a function that returns a stream, and then flattens those into one.
Correct Answer: b) To act as a container object for values that may or may not be present, avoiding NullPointerExceptions
Explanation:
Optional is a value-based class that forces developers to explicitly handle the case where a value might be null.
Correct Answer: b) ::
Explanation:
The double colon operator is the method reference operator, used to refer to a method without invoking it.
Correct Answer: c) To allow adding new methods to interfaces without breaking existing implementations
Explanation:
Default methods provide backward compatibility, allowing developers to add new methods to interfaces safely.
Correct Answer: c) Yes, and they are used to provide utility methods relevant to the interface
Explanation:
Java 8 introduced static methods in interfaces with implementations, primarily used as utility or helper methods.
Correct Answer: b) java.time
Explanation:
The java.time package provides a new, immutable, thread-safe Date and Time API.
Correct Answer: b) Automatic conversion of primitive types into their corresponding wrapper class objects
Explanation:
Autoboxing converts primitive types into their wrapper classes automatically (e.g., int to Integer).
Correct Answer: c) Pass-by-Value strictly
Explanation:
Java is strictly pass-by-value. For objects, the value passed is a copy of the reference to the memory location.
Correct Answer: b) The Heap Space
Explanation:
Objects are allocated in the Heap. An OutOfMemoryError usually means the heap is full.
Correct Answer: b) Infinite or overly deep recursive method calls
Explanation:
Each method call creates a new frame on the stack. Deep or infinite recursion exhausts the stack space.
Correct Answer: b) ClassNotFoundException occurs during explicit loading, while NoClassDefFoundError occurs during implicit linking at runtime
Explanation:
ClassNotFoundException happens during reflection (Class.forName). NoClassDefFoundError is thrown by the JVM when a linked class is missing.
Correct Answer: d) Dynamic ClassLoader
Explanation:
The three standard class loaders in Java are Bootstrap, Extension, and System ClassLoaders.
Correct Answer: a) It allows only a single instance of a class to be created per JVM
Explanation:
Singleton ensures that a class has only one instance and provides a global point of access to it.
Correct Answer: c) Factory
Explanation:
The Factory design pattern provides an interface for creating objects in a superclass, deferring instantiation to subclasses.
Correct Answer: c) Stack
Explanation:
Thread-specific data like local variables, method parameters, and return addresses are stored on the Stack.
Correct Answer: c) Metaspace
Explanation:
Java 8 removed the Permanent Generation (PermGen) and replaced it with Metaspace, which dynamically allocates from native memory.
Correct Answer: b) No, it is not synchronized and therefore not thread-safe
Explanation:
StringBuilder was introduced as a non-synchronized, faster drop-in replacement for StringBuffer in single-threaded scenarios.
Correct Answer: a) public void printArgs(String... args)
Explanation:
Varargs are specified by three dots after the type. They must be the last parameter in the method signature.
Correct Answer: c) long
Explanation:
A switch statement in classic Java supports byte, short, char, int, enum, and String, but does not support long, float, double, or boolean.
Correct Answer: c) Skips the current iteration and jumps to the next iteration
Explanation:
The continue statement bypasses the rest of the code in the current loop iteration and proceeds to the next evaluation.
Correct Answer: b) A break statement that terminates a specific labeled loop in nested loops
Explanation:
A labeled break allows breaking out of an outer loop from within a nested inner loop by referencing a label.
Correct Answer: b) 32 bits
Explanation:
In Java, an int is always a 32-bit signed two-s complement integer, regardless of the underlying platform.
Correct Answer: b) Double is 64 bits, float is 32 bits
Explanation:
A float is a single-precision 32-bit floating point, whereas a double is a double-precision 64-bit floating point.
Correct Answer: c) clone()
Explanation:
The clone() method from the Object class is used to create a copy of the object, provided the class implements Cloneable.
Correct Answer: a) Shallow copy copies references, deep copy copies actual objects
Explanation:
In a shallow copy, nested objects share the same memory reference. In a deep copy, completely independent copies are created.
Correct Answer: a) java.lang.Math
Explanation:
The java.lang.Math class contains static methods for performing basic numeric operations.
Correct Answer: a) Math.random()
Explanation:
Math.random() returns a double value greater than or equal to 0.0 and less than 1.0.
Correct Answer: b) A compact syntax for declaring data-carrying classes with immutable state
Explanation:
Records provide a concise way to create immutable data carriers, automatically generating getters, constructors, equals, and hashCode.
Correct Answer: c) It allows local variable type inference where the compiler deduces the type
Explanation:
The var keyword allows the compiler to infer the type of a local variable from its initializer, keeping Java statically typed.
Correct Answer: b) They are submitted as tasks using methods like execute() or submit()
Explanation:
With an ExecutorService, tasks are submitted via execute() or submit(), and the framework handles thread assignment.
Correct Answer: c) Variables that are local and independent to the specific thread that accesses them
Explanation:
ThreadLocal allows you to store variables that are only accessible to the specific thread that reads or writes them.
Correct Answer: b) Array can hold primitives, ArrayList can only hold Objects
Explanation:
Arrays have a fixed size and can hold primitives. ArrayList has a dynamic size and stores only objects.
Correct Answer: c) TimSort (a hybrid of Merge Sort and Insertion Sort)
Explanation:
Since Java 7, object arrays and collections are sorted using TimSort, which is stable and highly optimized.
Correct Answer: c) O(1)
Explanation:
Assuming a good hash function with minimal collisions, a HashMap provides constant time O(1) for get and put operations.
Correct Answer: b) Ensures that floating-point calculations result in the exact same values across all platforms
Explanation:
The strictfp keyword restricts floating-point calculations to ensure portability across different hardware architectures.
Correct Answer: b) catch
Explanation:
The catch block handles the exception that is thrown by the code within the try block.
Correct Answer: b) Yes, but they must be ordered from most specific to most general exception
Explanation:
If a general exception is placed before a specific one, the compiler throws an unreachable code error.
Correct Answer: b) A method written in another language and executed outside the JVM
Explanation:
The native keyword allows Java code to call functions written in languages like C or C++ via JNI.
Correct Answer: b) null
Explanation:
BufferedReader.readLine() returns a String containing the line, or null if the end of the stream is reached.
Correct Answer: c) They can be inherited by subclasses
Explanation:
Constructors are not inherited by subclasses. A subclass must call the superclass constructor explicitly or implicitly.
Correct Answer: c) Accessible within the same package and by subclasses in other packages
Explanation:
The protected modifier grants access to classes within the same package and to any subclass globally.
Correct Answer: a) An inner class that has no name and is instantiated in a single expression
Explanation:
Anonymous classes enable you to declare and instantiate a class simultaneously, often used for listeners.
Correct Answer: c) Singleton Pattern
Explanation:
The Singleton pattern ensures that a class has only one instance and provides a global access point.
Correct Answer: b) LinkedList
Explanation:
LinkedList implements the Queue and Deque interfaces, making it capable of acting as a FIFO queue.
Correct Answer: b) void
Explanation:
The wait() method, located in the Object class, pauses the thread and returns void.
Correct Answer: a) By using the synchronized keyword in the method signature
Explanation:
Placing the synchronized keyword in a method declaration locks the intrinsic monitor of the object or class.
Correct Answer: b) It throws an InterruptedException
Explanation:
If any thread interrupts a sleeping thread, the sleeping thread will wake up and throw an InterruptedException.
Correct Answer: c) When objects are no longer needed but are still referenced, preventing garbage collection
Explanation:
A memory leak happens when an application inadvertently holds onto object references that are no longer needed.
Correct Answer: c) G1 GC (Garbage-First Collector)
Explanation:
Starting from Java 9, G1 GC is the default garbage collector, optimized for multi-processor machines with large memories.
Correct Answer: b) An overridden method returning a subclass of the type returned by the original method
Explanation:
Java allows an overriding method to return a more specific subclass type than the overridden method.
Correct Answer: b) It returns a canonical representation for the string object from the string pool
Explanation:
Calling intern() checks if the string exists in the String pool and returns it, or adds it to the pool if it does not exist.
Correct Answer: b) An inner class is nested inside another class, a subclass inherits from another class
Explanation:
Inner classes deal with scope and containment, whereas subclasses deal with inheritance.
Correct Answer: b) No, it is strictly required by the JVM to launch the application
Explanation:
Since Java 7, the JVM explicitly checks for the main method before executing any static blocks.
Correct Answer: b) To manage object creation and the binding of dependencies externally
Explanation:
DI delegates the responsibility of instantiating dependencies to an external framework, promoting loose coupling.
Correct Answer: b) To inspect or modify the runtime behavior of applications and dynamically invoke methods
Explanation:
Reflection allows introspection of classes, interfaces, fields, and methods at runtime.
Correct Answer: b) extends
Explanation:
The extends keyword establishes class inheritance, creating an IS-A relationship.
Correct Answer: b) The application attempted to use an object reference that has the null value
Explanation:
Calling instance methods or accessing fields on a variable pointing to null triggers this unchecked exception.
Correct Answer: b) Removes all elements of the collection that satisfy the given predicate
Explanation:
removeIf() takes a Predicate and safely removes all items matching the condition.
Correct Answer: c) String
Explanation:
String objects in Java are immutable; their internal state cannot be changed after creation.
Correct Answer: d) All of the above
Explanation:
Private and static methods belong to the class and are hidden, while final explicitly locks a method against overriding.
Correct Answer: b) It produces bytecode stored in a class file
Explanation:
The Java compiler (javac) converts source files into .class bytecode files that the JVM can interpret.
Correct Answer: a) Arrays provide O(1) random access, LinkedLists require O(n) traversal
Explanation:
Arrays allocate continuous memory allowing direct O(1) index access, whereas LinkedLists require sequential node traversal.
Related Posts

Python Functions MCQs
Functions in Python are reusable blocks of code designed to perform a specific task, promoting code modularity, readability, and DRY…
August 27, 2026By MCQs Generator

Important Java 8 Features MCQs
Released in March 2014, Java 8 represents one of the most significant upgrades in the history of the Java programming…
October 19, 2026By MCQs Generator

Latest Python Dictionaries MCQs
Python dictionaries are built-in data structures used to store data in key-value pairs, providing fast lookups, insertions, and deletions. Keys…
October 19, 2026By MCQs Generator
Related Categories

AI & Data Science MCQ
5 topics
By MCQs Generator

Arts & Humanities MCQ
4 topics
By MCQs Generator

Civil Engineering MCQ
4 topics
By MCQs Generator

Commerce & Business MCQ
4 topics
By MCQs Generator

Competitive Exams MCQ
5 topics
By MCQs Generator

Electrical & Electronics Engineering MCQ
3 topics
By MCQs Generator

General Knowledge MCQ
2 topics
By MCQs Generator

General Science MCQ
4 topics
By MCQs Generator

Law & Judiciary MCQ
3 topics
By MCQs Generator

Mechanical Engineering MCQ
4 topics
By MCQs Generator

Medical & Health Sciences MCQ
4 topics
By MCQs Generator

Modern Tech Fields MCQ
3 topics
By MCQs Generator