Interface
Interface
Presented By
M.Thanga Aruna, AP/CSE
P.S.R. Engineering College,
Sivakasi
Interface
• An interface in java is a blueprint of a class.
• An interface contains behaviors that a class implements.
• It has static constants and abstract methods.
• The interface in java is a mechanism to achieve abstraction and
multiple inheritance.
• Interface is declared by using interface keyword.
• A class that implement interface must implement all the methods
declared in the interface.
Declaration
• To define an interface, we write:
public interface [InterfaceName] {
// declare constant fields
// declare methods that abstract by default
}
Relationship between classes and
interfaces
• A class extends another class, an interface extends another interface but a
class implements an interface.
Various ways of Interface
Implementation
Example
interface printable{
void print();
}