Is it possible to define marker interface in java.If possible
then how to define user defined marker interface?



Is it possible to define marker interface in java.If possible then how to define user defined mark..

Answer / dasharath

basically we use marker interface to make special type of object.
If we take an example of a book shop where we find different type of books, in that suppose you want to display all the books which are related to Java then you can use marker interface there.
You can create a Interface say JavaBooks which wont be having any methods(A blank interface), then all the classes(say for example I say MyJavaBook) implements this blank Interface.
And then while displaying all the books related to Java you can chk using instancOf whether the book is of type JavaBooks(Marker Interface which we created previously).

Is This Answer Correct ?    2 Yes 1 No

Post New Answer

More J2SE Code Interview Questions

we compile any program bu c:/>javac prog.java and run as c:/>java prog Here what's the meaning of c in javac. We have java Interpreter but not compiler.Then why we have to use javac. Please answer this question?

2 Answers  


Why the program getting error if we don't use String args[] in main(), even in the case of not getting any arguments from command line?

1 Answers  


Is it possible to define marker interface in java.If possible then how to define user defined marker interface?

1 Answers   Tech Mahindra,


Design a program using one-dimensional array that determines the highest value among the eight input values from a user. Display the difference of each value from the highest to the lowest.

1 Answers   RoboSoft,


For printing a message we use System.out.println in normal programs. We use String msg="text....."; Can't we use String msg=" " in normal programs and System.out.println("........") in applets. Please answer this question?

0 Answers  






I am trying to pass the string firstName from a Servlet called SampleServet. I am running this on eclipse and it tells me that "the value for annotation attribute must be a constant expression. I don't understand why it is giving me this error. @PersonAnnotation(name = SampleServlet.firstName) public class AnnotationClass{

0 Answers  


what are the other loops except for for,while,do while and until?

0 Answers   Aricent,


write a java program to create a Frame with three scrolls, change the back ground color of the frame using functions with values of scrolls.

0 Answers  


write a program in java to solve a system of n-variabled simultaneous equations using the guassian elimination method. let the maximum possible value of n be 100. run the program using hypothetical values for a set of 10- variables simultaneous equations. print out the program, the input equation and the results generated by the program.

0 Answers   TCS,


1+(2*3)+(4*5*6)+(7*8*9*10)+... specified input value

1 Answers   MAQ,


does anyone know the code to display a triangle using a applet?

1 Answers  


how to create a (*)pyramid using java codes???

5 Answers   Infosys,


Categories