JAVA interface mechanism
Others
2020-10-03 18:13:20
views: null
interface
- Describe what functions the class has, without giving a specific implementation
- The keyword is interface
- A class can implement one or more interfaces
- Does java support multiple inheritance, the answer is no java does not support multiple inheritance
- All methods in the interface are automatically public
Characteristics of the interface
- The interface is not a class and cannot be instantiated,
- Abstract classes cannot be instantiated
- Can declare variables of interface type
- Abstract classes can also declare variables of abstract types
- This variable must refer to an object that implements this interface
- Abstract class variables must refer to objects that inherit this abstract class
The difference between interface and abstract class
|
Abstract class |
interface |
Keyword |
abstract class |
interface |
inherit |
Only one abstract class can be inherited |
Multiple interfaces can be implemented |
area |
Can have instance domain |
Must not have instance domains |
method |
There can be ordinary methods |
There can only be static, default abstract methods |
Constructor |
Can have a constructor |
No |
purpose |
For reuse |
Decoupling |
Origin blog.csdn.net/Walker7143/article/details/106089502