
how marker interfaces work?

Hi Friend,
In java language programming, interfaces with no methods are known as marker interfaces. Marker interfaces are Serializable, Clonable, SingleThreadModel, Event listener. Marker Interfaces are implemented by the classes or their super classes in order to add some functionality.
e.g. Suppose you want to persist (save) the state of an object then you have to implement the Serializable interface otherwise the compiler will throw an error. To make more clearly understand the concept of marker interface you should go through one more example.
Suppose the interface Clonable is neither implemented by a class named Myclass nor it's any super class, then a call to the method clone() on Myclass's object will give an error. This means, to add this functionality one should implement the Clonable interface. While the Clonable is an empty interface but it provides an important functionality.
Example:
interface markerImp {
}
class MarkerTest implements markerImp{
}
public class TestInstanceOf {
public static void main(String []args){
MarkerTest mt = new MarkerTest();
if(mt instanceof markerImp){
System.out.println("True");
}
else{
System.out.println("False");
}
}
}
For more information, visit the following link:
Thanks

By implementing Serializable interface which has no methods and variables, how the class know to save the state of the object?
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.