In this tutorial, we will discuss interfaces in Java.
Interfaces
– refer to specific behavior or trait
– declares a fixed set of methods
– all implementing classes must define them
– used to refer multiple related or unrelated objects
– think of it as a contract that is to be adhered to
Features of interfaces in java
– Establishes the expected behavior
– Promotes flexibility in design
– Makes application more manageable
– Java 8 interfaces allow default and static methods in interfaces
Notes:
– A class can inherit from single base class
– A class can implement any number of interfaces
– An Interface can extend another interface
– An interface cannot define constructors like class
– Establishes the expected behavior
– Promotes flexibility in design
– Makes application more manageable
– Post Java 8
– Add more methods without breaking the existing implementations
– Provision for default methods
– Provision for static methods