/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package markerinterface;
/**
*
* @author Aravind Sankaran Nair
*/
public class MarkerInterface {
public static void main(String args[]){
MarkerImplementation markerImplementation=new MarkerImplementation();
if(markerImplementation instanceof FirstMarker) {
System.out.println(markerImplementation.display());
}
if(markerImplementation instanceof SecondMarker) {
System.out.println(markerImplementation.display());
}
}
}
interface FirstMarker{
}
interface SecondMarker{
}
class MarkerImplementation implements FirstMarker{
String display(){
return getClass().getInterfaces()[0].getSimpleName()+" interface is implimented";
}
}
Output:
FirstMarker interface is implimented
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package markerinterface;
/**
*
* @author Aravind Sankaran Nair
*/
public class MarkerInterface {
public static void main(String args[]){
MarkerImplementation markerImplementation=new MarkerImplementation();
if(markerImplementation instanceof FirstMarker) {
System.out.println(markerImplementation.display());
}
if(markerImplementation instanceof SecondMarker) {
System.out.println(markerImplementation.display());
}
}
}
interface FirstMarker{
}
interface SecondMarker{
}
class MarkerImplementation implements FirstMarker{
String display(){
return getClass().getInterfaces()[0].getSimpleName()+" interface is implimented";
}
}
Output:
FirstMarker interface is implimented
Please go through this blog for more details about Marker Interface http://adnjavainterview.blogspot.in/2014/06/what-is-marker-interface-in-java-why.html.
ReplyDelete