After you know the abstract class, look at the interface.
In Java, the content of an interface is primarily an abstract method, and of course it can contain properties (the properties defined in the interface are only constants by default): In general, the properties are not defined in the interface:
The interface keyword interface is a simple interface.
Defines an interface inter, which has a method show. Obviously, the method in the interface is also abstract, so we need to implement it.
How to implement the interface: implements.
Interfaces are used in the same way as abstract classes. Here we do not discuss the difference between the interface and the abstract class, left to the next talk
Considerations for the interface:
1. Interface, we can understand that it is a set of rules in Java, and the rules are fixed, and should not be changed.
2. According to 1, the attribute (variable) should be a constant
3. Only public abstract methods are allowed to exist in the interface. (void show () = public abstract void show) public abstract can be omitted
The advantages of the interface in fact, I think one thing: improve the expansion of the program.
Extensibility: USB jack on the computer. This is the interface, we can use this USB port to expand a variety of devices (audio, cell phones, etc.). The interface in the program you can use as a USB jack for your computer, as well as to expand new content.
It is also important to remember that the principle of interface is to prohibit modification, promote the expansion
Java-based interface