Abstract method and static method of java interface


before JDK1.8, interface did not provide any concrete implementation. It was described in JAVA programming ideas as follows: “interface is a keyword that produces a completely abstract class. It does not provide any concrete implementation at all. It allows the author to determine the method name, argument list, and return type, but does not have any method body. The interface provides the form, not any concrete implementation.

but this limitation is broken in JDK1.8, where interfaces allow you to define default methods and static methods.

code example

defines an IHello interface

public interface IHello {
	void sayHi();
	static void sayHello() {
		System.out.println("static method : say Hello!");
	default void sayByebye() {
		System.out.println("default method : say bye!");


defines an IHello interface implementation class

public class HelloImpl implements IHello {
	public void sayHi() {
		System.out.println("normal method:say hi");


method call

public class App 
	public static void main(String[] args)
    	HelloImpl helloImpl = new HelloImpl();
    	//default 方法只能通过实例对象来调用
    	//静态方法通过 接口名.方法名()来调用
    	//匿名实现类的好处:不用再单独声明一个类 缺点:由于没有名称。不能重复使用,只能使用一次
    	new IHello() {			
			public void sayHi() {
				System.out.println("normal method;say hi 新定义");			

normal method: say hi
default method: say bye!> static method: say Hello!
normal method: say hi new definition

Read More: