Question 31
What is a Marker Interface in Java?
Option A is correct. Marker interfaces (like Cloneable and Serializable) are empty interfaces used to 'tag' classes so that JVM or libraries apply special processing.
What is a Marker Interface in Java?
Option A is correct. Marker interfaces (like Cloneable and Serializable) are empty interfaces used to 'tag' classes so that JVM or libraries apply special processing.
Which non-access modifier in Java prevents an instance field from being serialized when an object is saved?
Option A is correct. The 'transient' keyword marks a member variable so that its state is skipped during object serialization into a byte stream.
What is the purpose of the 'volatile' keyword in Java multithreading?
Option B is correct. The 'volatile' modifier ensures variable changes are flushed to main RAM immediately, avoiding thread CPU cache inconsistencies.
Which Collection interface implementation in Java maintains elements in insertion order and allows duplicates?
Option C is correct. ArrayList implements List interface, maintaining insertion order and permitting duplicates and null values.
Which Set collection implementation in Java guarantees that elements are sorted in natural ascending order or via a Comparator?
Option C is correct. TreeSet is backed by a Red-Black tree structure, ensuring unique elements are sorted in natural or custom Comparator order.