GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java
Go To First  |  Previous Question  |  Next Question 
 Core Java  |  Question 497 of 502    Print  
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?


  
Total Answers and Comments: 4 Last Update: October 21, 2009     Asked by: Kamleshnit07 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: rajyalakshmi.d
 
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.

Above answer was rated as good by the following members:
stephenlai, ishnoddy, coolpintu
June 30, 2009 07:43:45   #1  
rajyalakshmi.d Member Since: June 2009   Contribution: 1    

RE: Marker Interface
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.

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
August 12, 2009 03:46:32   #2  
Sarje Member Since: August 2009   Contribution: 62    

RE: Marker Interface
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.
 
Is this answer useful? Yes | No
September 14, 2009 08:10:48   #3  
Saroj_mi2 Member Since: September 2009   Contribution: 1    

RE: Marker Interface
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.

 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 0Overall Rating: +2    
October 21, 2009 06:53:38   #4  
ae8166558de88 Member Since: October 2009   Contribution: 3    

RE: Marker Interface
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...

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape