Understanding of the interface

xiaoxiao2021-03-17  184

1, declare interface class

The declaration is as follows:

[Capsulate] Interface InterfaceName [Extends ParentsInterface]

{

[Capsulate] [Modified] Type Membervariable = Value;

[Capsulate] [Modifier] Returntype Fun (Parameter List);

}

note:

1. The interface class does not have a constructor.

2, MemberVariable defined in the interface class automatically declares into public static final. You cannot change any one, otherwise compile errors will occur.

3. The interface-defined FUN (parameter list) is also automatically coupled with the public field because he is a Abstract method.

4. The FUN declared in the interface class cannot be static, including main () cannot be added.

Note: Capsulate - Encapsulated Membervariable - Member Variables

ParentsInterface - parent interface class

2, inheritance of the interface class

1, Extends and Implements

The relationship between interfaces and classes is as follows:

Interface Extends Interface

Class Implements Interface

2, the interfaces of the interface are different from the class of Extends, which can extends multiple parent interfaces. Pay attention to the following:

<1>, multiple parent interfaces cannot have the same signature but return to different situations.

<2>, because the member variable of the interface is all static types, it is necessary to use the "class name. Field" using the member of the parent interface. If there is no classification and the parent interface has multiple identical this signature, it will compile errors.

<3>, there is no use in the interface class. Because the variables of the interface class are static, the variable of the parent interface is used with "parent interface. Variable". The method (FUN ()) does not implement a part, super () and this () are useless (all have a method in which the polymorphism is implemented.

转载请注明原文地址:https://www.9cbs.com/read-129713.html

New Post(0)