The Java Interface (java8 new features)



{class SubClassTest public

public static void main (String [] args) {
SubClass new new SubClass S = ();

// s.method1 ();
// SubClass.method1 ();
// knowledge 1: Static defined by the interface The method can only be called via the interface.
CompareA.method1 ();
// Knowledge Point 2: The object implementation class, you can default interface method calls.
// If the implementation class overrides the default interface methods, when called, the call is still after rewriting method
s.method2 ();
// Knowledge Point 3: If the parent class subclass (or implementation class) inheritance and the interface is declared with the same name as the default method parameters,
// so in the case of the subclass does not override this method, the default method is invoked the same name in the parent class with parameters. -> principle of giving priority class
// 4 knowledge: if the implementation class implements multiple interfaces, multiple interfaces which define the parameters of the default method with the same name,
in the case // then there is no override this method in the implementation class an error message. -> Interface conflict.
// This requires that we have to override this method implementation class
s.method3 ();

}

}

class SubClass the extends the SuperClass the implements CompareA, CompareB {

void method2 public () {
System.out.println ( "SubClass: Shanghai");
}

public void method3 () {
System.out.println ( "SubClass: Shenzhen");
}

// Knowledge Point 5: How subclass call (or implementation class) the method of the parent class, method interface is rewritten
public void the myMethod () {
the method3 (); // call to their overridden method defined
super.method3 (); // call is declared parent class
// call the default interface methods
CompareA.super.method3 ();
CompareB.super.method3 ();
}
}

Guess you like

Origin www.cnblogs.com/wpy188/p/12081687.html