"Crazy Java Lectures" 6

interface

1. The   interface defines the common behavioral norms common to multiple classes, and these behaviors are channels for communication with the outside. Because the interface defines a specification, it is decorated in the interface; defining class methods requires static modification.

3. The  interface supports multiple inheritance;

4.  A class can implement one or more interfaces, inheritance uses the extends keyword, and implementation uses the implements keyword.

5. After  a class implements one or more interfaces, the class must fully implement all abstract methods defined in these interfaces (that is, all abstract methods are rewritten).

6. The difference between abstract class and interface:

(1) Interfaces can only contain abstract methods, static methods, and default methods, and cannot provide method implementations for ordinary methods; abstract classes can contain ordinary methods.

(2) Interfaces can only define static constants, not ordinary member variables; both ordinary member variables and static constants can be defined in abstract classes.

(3) The interface does not contain a constructor; an abstract class can contain a constructor, but this constructor is not used to create objects, but to let other subclasses call these constructors to complete the initialization operations belonging to the abstract class.

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

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

Oh, what internal classes, Lambda, etc. will I talk about later,

If you don't want to see this, even if it is a pit, fill it in later.

Just so capricious hiahiahia~~~

 

Enumeration class

1.  The meaning of enumeration class: the instance is limited and fixed, such as the season class, there are only four objects.

2.  Java5 added a new enum keyword to define enumeration classes. An enumeration class is a special class, it can also have its own member variables, methods, can implement one or more interfaces, or define its own constructor.

3. Differences from ordinary classes:

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

(2) Enumeration classes cannot be derived from subclasses;

(3) The constructor of the enumeration class can only be modified with private;

(4) The instance of the enumeration class must be explicitly listed in the first line of the enumeration class, otherwise the enumeration class will never have an instance. When listing instances, the system will automatically add public static final decorations, without the programmer's explicit addition.

Give a chestnut:

image

Compiling the above program will generate a SeasonEnum.class file, which indicates that the enumeration class is a special Java class.

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

Give a chestnut:

image

 

The results are as follows:

image

 

end

image

[2017.07] I know that I don’t learn much today, and my state is actually not very good. I feel a little sleepy. If you study tomorrow, Chapter 6 should be over. In fact, I read many things and didn't write them out, because what I wrote is something that I really need to master. It's like the kind of things that can be read and impressed. There is no need to write them, so the content may be relatively small. Tomorrow Java, come on. I haven't gotten the competition questions for several days, so I have to get started. But I was a little frightened in my heart, and it didn't work. Come on!

It's holiday, happy holiday!

Guess you like

Origin blog.csdn.net/allein_STR/article/details/113986036