How many non-access modifiers are there in Java?
Java provides some other modifiers to provide the functionalities other than the visibility. These modifiers are called Non-Access Modifiers
- Static The members which are declared as static are common to all instances of a class. Static members are class level members which are stored in the class memory.
- Final This modifier is used to restrict the further modification of a variable or a method or a class. The value of a variable which is declared as final can’t be modified once it gets a value. A final method can not be overridden in the subclass and you can not create a subclass to a final class.
- Abstract This modifier can be used either with a class or with a method. You can not apply this modifier to variable and constructor. A method which is declared as abstract must be modified in the subclass. You can’t instantiate a class which is declared as abstract.
- Synchronized This modifier is used to control the access of a particular method or a block by multiple threads. Only one thread can enter into a method or a block which is declared as synchronized.
- Transient This modifier is used in the serialization process. A variable which is declared as transient will not be serialized during object serialization.
- Volatile volatile modifier is used in multi-threaded programming. If you declare a field as volatile it will be signal to the threads that it’s value must be read from the main memory rather then their own stack. Because volatile field is common to all threads and it will be updated frequently by multiple threads.
- Strictfp This modifier is used for floating-point calculations. This keyword ensures that you will get the same floating point presentation on every platform. This modifier makes floating point variable more consistent across multiple platforms.
Published on 23-May-2019 17:57:25