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 :
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.❮ Previous Next ❯