Do you know about defaults methods which got added to Java language in JDK 8 release? If yes then that’s very good but if you don’t then you have a good news. In this article we will cover everything you need to know about default methods. What are default methods? Let’s take a look at existing stuff first. As of Java 7, Java interface declares method/s which define a contract. Any class that implements the interface must provide an implementation for each method defined by the interface or inherit the implementation from a superclass. Note: These methods declared in the interface are implicitly public so you need not mention it in the declaration. Let’s see an example: interface Orderable { int getProduct( int serialNumber); String getProductSpecification(); float getPrice(); float getDiscount(); } Example of class implementing above interface public class Television implements Orderable { ...
Technical articles for developer community to help learn and use it at work to develop awesome solutions