Exams Knowledge Hub

MCQs for Competitive Exams, School & College Exams

Module: | Classes, Objects, OOPs & Inheritance

Q32: Consider the following statements regarding Marker Interfaces in Java:

1. A Marker Interface in Java is structurally defined as an entirely empty interface that contains absolutely no method signatures or constant field declarations.
2. The primary architectural purpose of a Marker Interface, such as java.io.Serializable, is to act as a flag to indicate to the JVM or compiler that the implementing class possesses a specialized capability.
3. Since Java 5, the core Java development community strictly recommends replacing all internal Marker Interfaces with empty Abstract Classes to heavily improve type safety during runtime compilation.

Which of the above statements is/are correct?
A
Only 1 and 2
B
Only 1 and 3
C
Only 2 and 3
D
1, 2, and 3
✅ Correct Answer: A
🎯 Quick Answer:
The correct combination is 1 and 2. Statement 3 is incorrect because the modern alternative to Marker Interfaces is the use of Java Annotations (e.g., @Serializable), not empty abstract classes.
Concept Definition: A Marker Interface is an empty structural type.
It does not enforce a behavioral contract (no methods to implement) but instead tags the class, allowing the Java Virtual Machine to recognize it during complex background operations.
Structural Breakdown: Common built-in Marker Interfaces include java.io.Serializable (allows object state to be saved to a byte stream), java.lang.Cloneable (allows safe memory duplication), and java.rmi.Remote.
Historical/Related Context: Before Annotations were introduced in Java 5, Marker Interfaces were the only mechanism developers had to attach metadata to a class.
For example, if an object attempted to cross a network boundary, the JVM would use the 'instanceof' operator to verify if the object implemented Serializable; if not, it threw a NotSerializableException.
Causal Reasoning: Using an empty Abstract Class as a marker is completely counterproductive because Java only supports single class inheritance.
If a developer used an abstract class as a marker, the target class would instantly exhaust its single inheritance limit, preventing it from extending any actual functional parent class.