Can anyone elaborate that what is the core difference between Null interface and Marker interface in Java. I have been asked this question in one of the interview.
Thanks.
Null interface is just another name for Marker Interface or the other way round. They are used interchangeably as far as I know.
These are just interface with no methods in them. Examples of marker interfaces are : Serializable
, Cloneable
.
Null interface is the example of marker interface.
Interface are different types. that are mainly extend interface, markble interface and marker interface.
Difference of marker Inteface and others are that marker interfaces has no methods..Example are;- serilizable-- for serialization. remote -- for remote method communication. your remote interface must extends this marker interface. when your remote interface extends marker interface then it is called as extend interface.
They just tell the compiler that the objects of this class need to be treated differently. some marker interfaces are : Serializable, Remote, Cloneable
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");
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With