Java interface methods
The interface can contain variables and methods. However, the variables in the interface are implicitly specified as public static final variables (and can only be public static final variables, and a compilation error will be reported when private modification is used ), the method is implicitly specified as a public abstract method and can only be a public abstract method (a compilation error is reported when other keywords such as private, protected, static, and final are used ), in addition, all methods in the interface cannot be implemented. That is to say, methods in the interface must be abstract methods.
These are well-known, but what I want to say is:
The call of the package enables the abstract methods in the interface to be used directly. For example, the methods in the Iterator interface can be called directly.
Collection c1 = new ArrayList ();
C1.add ("123 ");
C1.add ("456 ");
C1.add ("789 ");
Iterator it = c1.iterator ();
While (it. hasNext ();)
System. out. println (it. next ());
The call of the package is emphasized here.