What is?
It is the interface can have a default implementation, but do not need to achieve its implementation class method.
how to use?
In the former method plus default, static methods directly write the default implementation
1 / * 2 * default method . 3 * / . 4 public class DefaultMethod { . 5 public static void main (String [] args) { . 6 VO = VO new new VO (); . 7 vo.doSome (); . 8 VO.doSomeTwo () ; . 9 } 10 } . 11 12 is interface Operate { 13 is default void doSome () { 14 System.out.println ( "original version" ); 15 } 16 . 17 static void doSomeTwo () { 18 is System.out.println ( "abstract original version" ); . 19 } 20 is } 21 is 22 is class DB the implements Operate { 23 is 24 @Override 25 public void doSome () { 26 is System.out.println ( "first a rewritten version " ); 27 . Operate Super .doSome (); 28 } 29 30 public static void doSomeTwo () { 31 is System.out.println (" first abstract rewritten version " ); 32 Operate.doSomeTwo (); 33 is } 34 is } 35 36 class VO the extends DB { 37 [ 38 is @Override 39 public void doSome () { 40 System.out.println ( "second rewritten version" ); 41 is DB = DB new new DB (); 42 is db.doSome (); 43 is } 44 is 45 public static void doSomeTwo () { 46 is System.out.println ( "second abstract rewritten version" ); 47 DB.doSomeTwo (); 48 } 49 50 }
what is the benefit?
When prevent modification interface, the interface class needs to change all modifications