1. New features after Jdk8, default method
Public classJavainterfaceImplementsDemo01, demo02{//The default method must be replicated in the inherited interface@Override Public voideat () {Demo01.Super. Eat ();//calling the writing format of a method in an inherited interfaceDemo02.Super. Eat (); } Public Static voidMain (string[] args) {Newjavainterface (). Eat (); }}InterfaceDemo01 {default voideat () {System.out.println ("This is Demo01."); } }InterfaceDemo02 {default voideat () {System.out.println ("This is Demo02."); } }
If the class implements two or more interfaces, and two or more of these interfaces have the same default method, the implementing class must replicate the default method, or the compiler will fail, or if the class implements two or more than two interfaces, but a default method is unique to an interface. You can override or not rewrite the default method;
2. New features after Jdk8, static methods in the static method interface can directly use the interface call, but cannot be replicated or called in the implementation class of the interface, the class itself of the interface implementation class and its object cannot call the static method
Java-interface new Features