Modifiers in Java

Keywords for modifiers in Java 

In Java, there are several keywords used as modifiers to control the access, behavior, and characteristics of classes, methods, variables, and other program elements. Here are the commonly used modifiers in Java:


1. public: Accessible from anywhere, both within and outside the package.

2. private: Accessible only within the same class.

3. protected: Accessible within the same class, subclasses, and same package.

4. default (no explicit modifier): Accessible within the same package (package-private).

5. static: Belongs to the class rather than an instance of the class.

6. final: Indicates that a class cannot be subclassed, a method cannot be overridden, or a variable cannot be reassigned.

7. abstract: Can only be used with classes or methods. Indicates that a class is incomplete and must be extended (abstract class), or a method does not have an implementation (abstract method).

8. synchronized: Used for multithreading. Ensures that only one thread can access a synchronized block or method at a time.

9. volatile: Used for multithreading. Indicates that a variable's value may be modified asynchronously by different threads.

10. transient: Indicates that a variable should not be serialized when an object is being transferred over a network or saved to a file.

11. strictfp: Ensures that floating-point calculations are performed identically on all platforms.

12. native: Indicates that a method is implemented in a platform-specific code outside Java (usually written in languages like C or C++).

                                                      

Java modifiers, Access modifiers
Keywords for modifiers in Java, How many keywords are there for modifiers in Java

These modifiers are used to define the behavior, accessibility, and characteristics of classes, methods, variables, and other elements in Java programs.

Post a Comment

0 Comments