Wednesday 3 August 2016

Interface:

Interface is the blueprint for the class. It is a perfect example for Abstraction. It contains method which are abstract. Since its abstract the method will have only declaration and no method body.
All the data members of the interface are final and static by default and all the methods are abstract by default.

Interface can be implemented in a class. The class should contain the implementation of all the abstract methods.

Example:

public interface Animal{
int i = 4; //final and static
public void legs();
public void eat();
}

public class Lion implements Animal{
public void legs(){
System.out.println("Lion has "+i+" legs");
}
public void eat(){
System.out.println("Lion is a carnivorous");
}
}


Marker Interface:
Marker interface is an interface which is empty without any abstract method declaration.

public interface marker{
}

No comments: