0 votes
in JAVA by
What is marker interface in java?

1 Answer

0 votes
by

What is marker interface in java?

An empty interface in Java is known as a marker interface i.e. it does not contain any methods or fields by implementing these interfaces a class will exhibit a special behaviour with respect to the interface implemented. If you look carefully on marker interface in Java e.g. Serializable, Cloneable and Remote it looks they are used to indicate something to compiler or JVM. So if JVM sees a Class is Serializable it done some special operation on it, similar way if JVM sees one Class is implement Clonnable it performs some operation to support cloning. Same is true for RMI and Remote interface. In simplest Marker interface indicate, signal or a command to Compiler or JVM.

–> Practically we can create an interface like a marker interface with no method declaration in it but it is not a marker interface at all since it is not instructing something to JVM that provides some special behaviour to the class when our program is going to execute.

For example Serializable, Cloneable etc..are marker interfaces

When my program gets executed, JVM provides some special powers to my class which has implemented the Marker Interfaces.

🔗Reference : stackoverflow.com

🔗Source: Java Interview Questions and Answers

🔗Reference: Javatpoint.com

Related questions

+1 vote
asked Apr 15, 2021 in JAVA by SakshiSharma
+1 vote
asked Oct 11, 2020 in JAVA by SakshiSharma
...