Skip to main content

Posts

JAVA Interface

What is it? Java interface is a bit like a class, except you can only declare methods and variables in the interface. You cannot actually implement the methods. It is a collection of abstract methods. Interfaces are a way to achieve polymorphism in Java. Interface is declared using the Java keyword interface. Interface can be declared public or package scope (no access modifier). If the class that implements the interface is abstract, all the methods of the interface need to be defined in the class. When a class implements an interface, you can think of the class as signing a contract, agreeing to perform the specific behaviors of the interface. If a class does not perform all the behaviors of the interface, the class must declare itself as abstract. A class can implement more than one interface at a time. The methods must have the exact same signature (name + parameters) as declared in the interface. Th...