What is Static Keyword in Java ?

Comments · 21 Views

The static keyword in Java is mainly used in Java for memory management. The "Static" keyword is used in Java to share the same variable or method of a specific class. Users can apply static keywords with variables, methods, blocks, and nested classes. The keyword static belong

The static keyword is a Java no-access modifier that applies to:

blocks
variables
methods
classes

Characteristics of the static keyword:
Here are some characteristics of the static keyword in Java:

Shared memory allocation : Static variables and methods allocate memory only once during program execution. This memory is shared by all instances of the class, making static members useful for maintaining global state or shared functionality.

Java Course in Solapur 

Accessible without object instantiation: Static members can be accessed without instantiating a class. This makes them useful for providing helper functions and constants that can be used throughout the program.
Bound to class, not to objects: Static members are bound to the class, not to individual objects. This means that changes to a static member are reflected in all instances of the class, and static members can be accessed by class name rather than an object reference.

Cannot access non-static members: Static methods and variables cannot access non-static members of the class because they are not associated with a specific instance of the class.

Can be overridden but not overridden: Static methods can be overridden, which means you can define multiple methods with the same name but different parameters. However, they cannot be overridden because they are associated with the class and not with a specific instance of the class.

Java Training in Solapur

Comments