Null vs Marker Interface

Can anyone explain what is the main difference between the Null interface and the Marker interface in Java. I was asked this question in an interview.

Thanks.

+7
source share
4 answers

Null interface is just another name for the Token interface or vice versa. As far as I know, they are used interchangeably.

It is just an interface without any methods. Examples of marker interfaces: Serializable , Cloneable .

+5
source

The null interface is another name for the marker interface. Such an interface is empty, that is, without any method descriptions.

For example, Serializable, Cloneable class in java. In earlier versions of Java, Marker interfaces were the only way to declare class metadata.

+2
source

Zero interfaces are marker interfaces, they do not have function declarations, they are empty interfaces, this means telling the compiler that they need to be treated differently.

+1
source

The null interface is an example of a marker interface.

An interface is a different type. which basically extend the interface, the markble interface, and the marker interface.

The difference between Inteface and others is that marker interfaces have no methods. For example: - serializable - for serialization. remote - for remote communication. Your remote interface should extend this token interface. when your remote interface extends the token interface, it is called the advanced interface.

They simply tell the compiler that objects of this class need to be treated differently. some marker interfaces: Serializable, Remote, Cloneable

the code:

 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"); } } } 
0
source

All Articles