Marker Interface in java is an interface with no fields or methods within it. It is used to convey to the JVM that the class implementing an interface of this category will have some special behaviour. Hence, an empty interface in java is called a marker interface. Marker interface is also called tag interface by some java gurus.

Let's see a program what exactly a marker interface is :

Example

interface P
{
}
class MarkerDemo implements P
{
void show()
{
System.out.println("JavaRace");
}
}
class Mark
{
public static void main(String args[])
{
MarkerDemo obj=new MarkerDemo();
if(obj instanceof P)
obj.show();
else
System.out.println("not permission");
}
}

Output:

JavaRace

Here the object obj is created by MarkerDemo class which is also indirectly created by the interface P. Suppose I don’t want to print hello directly by calling show() method, I need some permission, that’s why we give some permission to the class MarkerDemo. If the object obj is the instance of P, then the method show() is called, otherwise else statement will be executed. So here if condition is true so the output is JavaRace.

Our Services:

Java Training | Python Training | Machine Learning with Python Training | Deep Learning with Python Training | Projects

SILAN Technology
Call to: 9439202111  |  9658317757  |  0674-2361252

Comment