In Java, a class can extend multiple other classes, achieving multiple inheritance.
Correct Answer
False
Java supports single inheritance for classes; a class can only extend one other class. Multiple inheritance of implementation is not allowed to avoid the diamond problem.
Question 2
Encapsulation in Java allows restricting direct access to an object's internal state, typically by making fields private and providing public getter/setter methods.
Correct Answer
True
Encapsulation is the practice of bundling data and methods that operate on the data within a single unit, and restricting direct access to some of the object's components.
Question 3
An abstract class in Java cannot have any concrete (non-abstract) methods.
Correct Answer
False
An abstract class can have both abstract and concrete methods. It is not required for all methods to be abstract.
Question 4
The 'protected' access modifier allows a member to be accessed only within its own class and by subclasses, regardless of the package.
Correct Answer
False
The 'protected' access modifier allows a member to be accessed within its own class, by subclasses (even in different packages), and by other classes within the same package.
Question 5
In Java, an interface can extend multiple other interfaces.
Correct Answer
True
An interface can extend multiple other interfaces, allowing it to inherit method signatures from all of them. This is a form of multiple inheritance of type.
Question 6
A 'Set' in Java collections guarantees that elements are stored in the order they were inserted.
Correct Answer
False
A 'Set' does not guarantee any specific order of elements. Implementations like 'LinkedHashSet' maintain insertion order, but the 'Set' interface itself does not.
Question 7
'ArrayList' in Java is generally more efficient for adding or removing elements from the middle of the list compared to 'LinkedList'.
Correct Answer
False
'LinkedList' is generally more efficient for adding or removing elements from the middle of the list because it only requires updating pointers, while 'ArrayList' requires shifting all subsequent elements.
Question 8
The 'HashMap' class in Java ensures that its keys are stored in a sorted order.
Correct Answer
False
'HashMap' does not guarantee any order of its keys. 'TreeMap' is the collection class that stores keys in a sorted order.
Question 9
An 'Iterator' in Java collections provides a way to access elements of a collection sequentially without exposing its underlying representation.
Correct Answer
True
The 'Iterator' interface allows for sequential access and removal of elements from a collection.
Question 10
The 'ConcurrentHashMap' class is a thread-safe alternative to 'HashMap' that does not block the entire map for read operations.
Correct Answer
True
'ConcurrentHashMap' provides thread-safe operations without synchronizing the entire map, allowing concurrent read and limited concurrent write operations.
Question 11
A 'RuntimeException' in Java must be declared in a method's 'throws' clause or handled using a 'try-catch' block.
Correct Answer
False
'RuntimeException' and its subclasses are unchecked exceptions, meaning they do not need to be explicitly declared in a 'throws' clause or caught in a 'try-catch' block by the programmer, though they can be.
Question 12
The 'finally' block in a 'try-catch-finally' statement is guaranteed to execute whether an exception occurs or not, even if the 'try' or 'catch' block contains a 'return' statement.
Correct Answer
True
The 'finally' block is always executed, regardless of whether an exception is thrown or caught, or if a 'return' statement is encountered within the 'try' or 'catch' blocks.
Question 13
It is possible for a 'catch' block to handle multiple types of exceptions using a single 'catch' clause in Java 7 and later.
Correct Answer
True
Java 7 introduced multi-catch blocks, allowing a single 'catch' clause to handle multiple exception types separated by a vertical bar (|).
Question 14
All custom exceptions in Java must directly extend 'Exception'.
Correct Answer
False
Custom exceptions can extend 'Exception' (making them checked exceptions) or 'RuntimeException' (making them unchecked exceptions), or any of their subclasses.
Question 15
Due to type erasure, generic type information is available at runtime when inspecting objects.
Correct Answer
False
Due to type erasure, generic type information is only present at compile time and is removed during compilation, so it is not available at runtime for inspection of generic types on objects.
Question 16
Wildcards like '<? super Integer>' can be used to add 'Integer' objects to a generic collection.
Correct Answer
True
A wildcard with a lower bound like '<? super Integer>' allows adding 'Integer' objects (or any subtype of Integer, though Integer is final) to the collection, as it ensures type safety for consumer operations.
Question 17
Generic methods in Java allow type parameters to be declared before the return type of the method.
Correct Answer
True
Generic methods declare their type parameters between the method's modifiers (e.g., 'public static') and its return type (e.g., 'public static <T> List<T> getList()').
Question 18
Using raw types (e.g., 'List' instead of 'List<String>') can lead to 'ClassCastException' at runtime.
Correct Answer
True
Raw types bypass compile-time type checking, allowing incompatible types to be inserted into a collection, which can then lead to a 'ClassCastException' when elements are retrieved and cast.
Question 19
The 'synchronized' keyword in Java ensures that only one thread can execute a block of code or method at a time on a given object instance.
Correct Answer
True
The 'synchronized' keyword provides mutual exclusion, ensuring that only one thread can hold the lock for a specific object or class at any given time, thus preventing concurrent access to shared resources.
Question 20
Using the 'volatile' keyword on a field guarantees both atomicity and visibility of changes to that field across threads.
Correct Answer
False
The 'volatile' keyword guarantees visibility of changes to a field across threads but does not guarantee atomicity for compound operations (like incrementing a counter). It only ensures that reads and writes to the variable are directly to and from main memory.
Question 21
A 'Runnable' object can be executed by directly calling its 'run()' method, which will create a new thread for its execution.
Correct Answer
False
Calling the 'run()' method directly executes the code in the current thread, not a new one. To execute it in a new thread, you must pass the 'Runnable' to a 'Thread' constructor and then call the 'start()' method of the 'Thread' object.
Question 22
The 'ExecutorService' framework provides a higher-level abstraction for managing threads than manually creating and starting 'Thread' objects.
Correct Answer
True
'ExecutorService' decouples task submission from task execution, providing mechanisms for managing a pool of worker threads, scheduling tasks, and managing their lifecycle, which is more robust than direct 'Thread' management.