Java provides some other modifiers to provide functionality beyond visibility. These modifiers are called non-access modifiers
- staticMembers declared as static are common to all instances of the class. Static members are class-level members that are stored in class memory.
- FinalThis modifier is used to restrict further modifications to a variable, method, or class. The value of a variable declared final cannot be modified once it obtains its value. Final methods cannot be overridden in subclasses, nor can you create subclasses of the Final class.
- AbstractThis modifier can be used with a class or method. You cannot apply this modifier to variables and constructors. Methods declared abstract must be modified in subclasses. You cannot instantiate a class declared abstract.
- SynchronizationThis modifier is used to control access to a specific method or block by multiple threads. Only one thread can enter a method or block declared as synchronized.
- TransientThis modifier is used in the serialization process. Variables declared as transient are not serialized during object serialization.
- VolatileThe volatile modifier is used in multi-threaded programming. If you declare a field as volatile, it signals to threads that its value must be read from main memory rather than from their own stack. Because volatile fields are common to all threads and will be updated frequently by multiple threads.
- StrictfpThis modifier is used for floating point calculations. This keyword ensures that you get the same floating point representation on every platform. This modifier makes floating point variables more consistent across multiple platforms.
The above is the detailed content of How many non-access modifiers are there in Java?. For more information, please follow other related articles on the PHP Chinese website!