Java MCQ: Which of the following is a marker interface in Java?
Answer:
Explanation:
In Java, a marker interface is an interface that does not contain any methods or fields. Its purpose is to provide metadata to the Java runtime or other classes about the objects that implement the interface.
Both Serializable
and Cloneable
are examples of marker interfaces in Java. The Serializable
interface indicates that a class can be serialized, which means converting an object into a byte stream for storage or transmission. The Cloneable
interface indicates that a class supports cloning, which allows objects to be copied.
Implementing these marker interfaces in a class allows the Java runtime to treat objects of that class differently, based on the capabilities indicated by the marker interface.
Reference links:
https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html