- Java Interface can contain only method declarations and public static final constants and doesn't contain their implementation. The classes which implement the Interface must provide the method definition for all the methods present.
- An Interface definition begins with the keyword "interface".
- Interfaces are useful in a situation when all its properties need to be implemented by subclasses
- All variables in an Interface are by default - public static final
- An Interface can only have public members
- The problem with an interface is, if you want to add a new feature (method) in its contract, then you MUST implement those method in all of the classes which implement that interface.
Example:
interface MyInterface{
public void getOne();
public void getTwo();
}
public class MyClass implements MyInterface{
public void getOne(){
...............................
...............................
}
public void getTwo(){
...............................
...............................
}
}
Marker Interface:
The Marker interface is an empty interface,another way is the marker interface makes the underlying JVM and JRE container provide special run time capabilities to the objects of it's implementation class is called marker interface.
some marker interfaces are listed bellow:
- java.lang.Serializable
- java.lang.Remote
- java.lang.Cloneable
- java.lang.Externalizable

No comments:
Post a Comment