interface

1. An interface defines the common behavior of multiple classes that act as a channel for communication with the outside world. Because the interface is defined as a specification, the interface is decorated; To define a class method, you need the static modifier.

3. The interface supports multiple inheritance.

4. A class implements one or more interfaces using the extends keyword and implements the implements keyword.

5. After a class implements one or more interfaces, the class must fully implement (override) all of the abstract methods defined in those interfaces.

6. The difference between abstract classes and interfaces

(1) The interface can only contain abstract methods, static methods and default methods, can not provide method implementation for common methods; Abstract classes can contain ordinary methods.

(2) The interface can only define static constants, not ordinary member variables; Abstract classes can define both ordinary member variables and static constants.

(3) The interface does not contain a constructor; An abstract class can contain constructors, but instead of creating objects, other subclasses call these constructors to perform initialization operations that belong to the abstract class.

(4) The interface does not contain initialization blocks, but the abstract class can contain initialization blocks.

(5) A class has at most one direct parent class, including abstract class; But a class can directly implement multiple interfaces.

Oh, I’m going to talk about inner classes, Lambda,

If you don’t want to see this, it’s a hole. Fill it out later.

So capricious Hiahiahia

 

Enumeration class

1. What enumerated classes mean: Instances are finite and fixed, such as the season class, which has only four objects.

2. Java5 adds an enum keyword to define enumerated classes. Enumerated classes are special classes that can also have their own member variables, methods, implement one or more interfaces, and define their own constructors.

3. Differences with common classes:

(1) Enumeration classes cannot explicitly inherit from other parent classes;

(2) Enumeration classes cannot be derived from subclasses;

(3) The constructor of an enumerated class can only be private;

(4) Instances of an enumerated class must be explicitly listed on the first line of the enumerated class, otherwise the enumerated class will never have an instance. When an instance is listed, the public Static Final modifier is automatically added without the programmer having to add it explicitly.

Here’s an example:

Compiling the above program produces a seasonen.class file, indicating that the enumerated class is a special Java class.

If you need an instance of this enumerated class, you can use the form EnumClass.variable

Here’s an example:

 

The results are as follows:

 

end

[2017.07] I know I haven’t learned much today, and I’m not in a good state. I feel a little sleepy. If I study tomorrow, I think chapter six will be over. In fact, I did not write out a lot of things after reading them, because what I wrote is what I really need to master, like the kind of things that just look at and have an impression, there is no need to write out, so maybe the content is relatively little. Java refueling tomorrow, several days have not done the competition, must get started. But the in the mind a little afraid afraid of it, as expected or not. Come on!

Holiday, happy holiday!