dcsimg
 

Default Methods in Java Interfaces

Tuesday May 11th 2021 by MS Sridhar
Article Image

Here is an example of an implementation of a default method in a Java interface.

Prior to Java 8, interfaces in Java typically did not have any definitions. That changed starting with Java 8, where defining interface methids was made possible. There are are multiple reasons why you would want to add a definition to your Java methods. Below, we demonstrate how to define a default method in Java interfaces.

*/


public interface DefaultMethodInterface {

	default void print() {
		System.out.println("I am the default method in the interface!");
	}
	
}	
Home
Mobile Site | Full Site