
Before Java 8, no method with a body was allowed at all. Needless so say, the introduction of new features in Java 8 has completely changed the definition of Java Interface. For example, the introduction of default and static methods in Java Interface. Additionally, what are the changes introduced in newer versions of JDK, especially in JDK8. You are expected to know about Java Interface in a deeper way. Even you may not be a good Java Programmer, if you have not learnt each aspect of a Java Interface. As a beginner, if not, actually you have not learnt the Java language properly.
#Java interface rules professional
It is called multiple inheritances.Either you are a beginner or a professional in Java programming language, you must have come across the term Java Interface.
#Java interface rules code

📍 What are common rules to implement an interface?ġ.Fields in interfaces are public, static and final implicitly.Ģ.Method in an interface are public implicitly.ģ.A class can implement multiple interfaces.Ĥ.The overriding methods can not have more restricted access specifiers.ĥ.Non-abstract classes must override all methods declared in the super interfaces.Ħ.An interface can extend another interface, not a class.ħ.An interface can be nested in a class or interface.Ĩ.Methods in an interface can not be static and final.ĩ.An Interface can have default methods and static methods.ġ0.Functional interface is an interface which have only one method.ġ1.Marker interface is an interface with Zero methods, used to inform JVM about specific needġ.Functional Interfaces : Functional Interface is an interface that has only pure one abstract method.Ģ.Marker Interfaces : An interface that does not contain any methods, fields, Abstract Methods, and any Constants is Called a Marker interface.ģ.General Purpose Interfaces: Interfaces with all the required properties like multiple abstract methods, private methods, private static methods etc. The nested interfaces can only have public and default access specifier. The nested interface must be referred to by the the outer interface or class. Nested interfaces are used to group related interfaces so that they can be easy to maintain. These methods are generally used as utility methods which helps other defined methods inside that interface The purpose of adding private methods in interfaces is to improve the code re-usability. Static methods in JAVA 8 can not be private, but from JAVA 9 it can be.įrom JAVA 9 onwards an interface can have following components in it: JAVA 9 introduced private and private static methods in interfaces. It allows developers to add new methods to interface without affecting the classes which implements those interfaces.įrom JAVA 8 onwards an interface can have following components in it:

Prior to JAVA 8, interfaces can only only have public and abstract by default. Inclusion of static & default method in interface. 📍 What are changes in interfaces after JAVA 8 and JAVA 9 ? Implementation of the Bicycle interface Class implementing interface is responsible to provide implementation of methods. Methods forms the objects interface with outside world.

Objects interact with outside world with the help of methods that they expose. It provides communication contract between two objects It works as a contract that to be implemented by the interfaces implementing class. When a class implements a certain interface, it promises to provide implementation to all the abstract methods declared in the interfaces.
