Interface
Elicit interfaces: We find that there are no inherited classes, and there are behaviors that can be shared. An interface is a new mechanism that is independent of the class and focuses on behavior.
when we find that behavior is common among multiple classes that do not have an inheritance relationship, we need to extract it into the interface instead of the parent class.
define interface--keyword interface class name +able
Property--can only public static constant property--------------The three keywords that do not write the static final are also default
Public static final int a = +;
public static int b = n;
public int c = +;
int d = n;
Constructs---Interfaces cannot have constructs, that is, interfaces cannot produce objects
interface function:
1. Let the class implement the interface, use the Implement keyword, and rewrite the abstract method in the interface
2. If a class implements an interface, but cannot implement all of its abstract methods, it can only be an abstract class
3. A class can implement multiple interfaces while inheriting the parent class
The behavior---can only be public abstract methods---even if the modifier is not written by default, this indicates that the interface's concerns and richness are reflected in the method.
after Jdk1.7, the interface is allowed to have an implemented method, but the default keyword must be used, and the meaning of the interface is here---let the class without the inheritance relationship share these
behavior, each has its own realization.
Note the points:
1. Interface can inherit interface, but multiple inheritance, still use extends keyword
2. Interface as far as possible to define a small interface--Interface Isolation principle
3. Interface applied to polymorphic, interface reference = object that implements the class
column: Serviceable ser = new Newmachine ();
4. If you do not implement an interface, even if you have the same method, you cannot use the interface reference to point to
comparing abstract classes with interfaces
Abstract class:
1. Abstract class definition
2. Syntax, abstract method must be an abstract definition
3. Can have attributes, construction methods, can have implemented methods
4. Using syntax: Inheriting abstract classes with subclasses, extends
5. Design time; The innate method is written in abstract class
Interface:
1. Define with Interface
2. Cannot have variable attribute, property can only be static public constant, cannot have construct
3.jdk1.7 can be implemented after the method but must add the default
4. Class can implement interface with implements, interface can inherit interface with extends
5. Design-Time: Subsidiary Add method written in interface
[Summary] 2016.12.8 Thursday