Warning: Use of undefined constant fixed - assumed 'fixed' (this will throw an Error in a future version of PHP) in /home/webtro13/domains/farenda.com/public_html/wp-content/themes/moments/header.php on line 65
class="header_container_flat">

Default methods in interfaces

Default methods in Java 8 interfaces provide real implementations and can be overridden in classes implementing them. So, interfaces became something like abstract classes, except that their methods are public (abstract classes can have public, protected, default, and private) and you can implement multiple interfaces, whereas only one abstract class can be extended.

Purpose of default methods in interfaces

The purpose of default methods is to allow programmers to extend their libraries without breaking existing code bases. Notice how many new methods have been added to java.util.Collection and java.util.Map interfaces without breaking classes implementing them. You will see more use in articles about Java 8 Lambdas and Streams!

Example interface in Java 8

The following interface is a sample interface taken from JDK 8. It has abstract method, default methods, and static method. All in one: