Available modifiers for classes, methods, member variables, and local variables
Modifiers |
Class |
Member Methods |
Construction method |
Member variable |
Local variables |
Abstract |
Y |
Y |
_ |
_ |
_ |
Static |
_ |
Y |
_ |
Y |
_ |
Public |
Y |
Y |
Y |
Y |
_ |
Protected |
_ |
Y |
Y |
Y |
_ |
Private |
_ |
Y |
Y |
Y |
_ |
Synchronized |
_ |
Y |
_ |
_ |
_ |
Native |
_ |
Y |
_ |
_ |
_ |
Transient |
_ |
_ |
_ |
Y |
_ |
Volatile |
_ |
_ |
_ |
Y |
_ |
Final |
Y |
Y |
_ |
Y |
Y |
1, access control modifier:
The Java language uses access control modifiers to control the access rights of classes and classes ' methods and variables, exposing only the interface to the consumer, but hiding the implementation details.
Public level: To be publicly decorated, externally
Protected level: Protected decorated, exposing to subclasses and classes in the same package
Default level: No access control modifiers are exposed to classes in the same package
Private level: Decorated with private, only the class itself can be accessed, not public
The top-level class has only the default or public level, so it cannot be decorated with private and protected.
2, abstract modifier:
Used to modify class and member methods, abstract classes cannot be instantiated, and abstract methods do not provide specific implementations.
Abstract classes can have no abstract methods, but classes that contain abstract methods must be defined as abstract classes
If the subclass does not implement all of the abstract methods in the parent class, then the subclass must also be defined as an abstract class
No abstract construction method, no abstract static method
Abstract classes can have non-abstract construction methods that may be invoked when instances of subclasses are created
Abstract classes and abstract methods cannot be decorated with the final modifier (why?) )