Marker Interface

When there is no methods in the marker interface, then what is the use of marker interface. What is the functionality of the interface. Why do we need to implement marker interface?

Questions by Kamleshnit07

Editorial / Best Answer

Saroj_mi2  

  • Member Since Sep-2009 | Sep 14th, 2009


Marker interface is an interface with out having any implementation methods.
By implementing this interfaces, we will specify some special behaviour to implemented class.

Examples: Serializable, Cloneable
For example if we want to create a clone for a an object of class using clone()(clone()-- which is an object class method), then class need to implement Cloneable interface.

 This mark is to JVM to handle the interface.If you are implimenting this interface the compliler will know some specific job need to be done.
For Cloneable interface even it does not have any methode the JVM looks for clone() method to execute.
But the complier will not fail if the clone() meth is not implimented.

Showing Answers 1 - 0 of 0 Answers

Marker interface is an interface with out having any implementation methods.
By implementing this interfaces, we will specify some special behaviour to implemented class.
Examples: Serializable, Cloneable
For example if we want to create a clone for a an object of class using clone()(clone()-- which is an object class method), then class need to implement Cloneable interface.

Sarje

  • Aug 12th, 2009
 

Mraker interfaces are used to tag (mark) a class that the class possess a particular behaviour. For example to save the sate of an object the class must mark with (or implement)  the java.io.Serializable.

Saroj_mi2

  • Sep 14th, 2009
 

Marker interface is an interface with out having any implementation methods.
By implementing this interfaces, we will specify some special behaviour to implemented class.

Examples: Serializable, Cloneable
For example if we want to create a clone for a an object of class using clone()(clone()-- which is an object class method), then class need to implement Cloneable interface.

 This mark is to JVM to handle the interface.If you are implimenting this interface the compliler will know some specific job need to be done.
For Cloneable interface even it does not have any methode the JVM looks for clone() method to execute.
But the complier will not fail if the clone() meth is not implimented.

If a class implements any interface than the object of that class is also interface type, i.e. object instanceof interface is true. And when an Object is required to be treated in some specific functionality say cloning or serialization the object is first checked that the object is eligible to be used for that type of functionality. If no special method is required in object the interface is kept with no method and is called Marker interface.
e.g. in ObjectOutputStream object is checked with if (obj instanceof Serializable)

these are my views only don't know what actual intention java creaters had...

uncer

  • Jan 15th, 2010
 

When you need to perform some behavioral function on any class without implementing method in implemented interface we implement an interface such interface called marker interface for exmple serializabe, cloneable.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions