Which data structure is best suited for implementing a Last-In-First-Out (LIFO) order of elements in Java?
Stack
Set
Queue
Map
Which interface must a class implement to be eligible for serialization in Java?
Parcelable
Iterable
Cloneable
Serializable
What OOP concept is demonstrated when a single method call behaves differently depending on the object's type?
Polymorphism
Encapsulation
Abstraction
Inheritance
How can you access the value of an annotation's element at runtime?
By accessing the annotation element directly as a field of the annotated element
By casting the annotated element to the annotation type
By using the getAnnotation() method
getAnnotation()
By using the getDeclaredAnnotation() method
getDeclaredAnnotation()
Can a static inner class access non-static members of its outer class directly?
No
Yes
In Java NIO, what is the purpose of a Selector?
Selector
It serializes and deserializes objects to and from NIO channels.
It represents an open connection to a file for reading or writing data.
It manages multiple channels and allows for efficient handling of I/O events.
It provides a buffer for storing data read from or written to a channel.
Which List implementation in Java uses a dynamic array to store elements and provides fast access to elements by their index?
List
Vector
LinkedList
ArrayList
What happens when a generic class is instantiated with a primitive type in Java?
A runtime exception is thrown.
The primitive type is autoboxed to its wrapper class.
A compile-time error occurs.
It works as expected.
What is the time complexity of retrieving an element from a HashSet in Java, assuming the hash function distributes elements evenly?
O(n log n)
O(1)
O(log n)
O(n)
Which Java method would you use to find the index of the first occurrence of a specific substring within a string?
indexOf()
substring()
length()
charAt()