❮ Previous Next ❯

Marker Interface in Java

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.

❮ Previous Next ❯



  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved