What is Interface:
An interface in Java is a reference type that contains abstract methods and defines a contract that implementing classes must fulfill.
Methods Are Public and Abstract by Default, so they will not be written with the Abstract and public as keywords at the front.
A class can use the Implements keyword to extend a contract
After Java 8, interfaces can have default methods. If a class implements two interfaces that contain default methods with the same signature, the class must override the method and explicitly specify which interface method to call using
InterfaceName.super.methodName();
Things NOT Allowed in Interface:
Cannot create an Object of an interface, because the interface is incomplete. When you create an object, you should be able to access incomplete methods, and that should not be allowed.
Cannot Have a Constructor
Cannot Have Instance Variables
Cannot Have Non-Abstract Normal Methods (Before Java 8)
Cannot Be Declared as Final
Top comments (0)