Static Keyword in Java Programming

Static keyword in Java is a non-access modifier that helps to modify the meaning of a variable, method, or class.

Java contains various types of keywords or modifiers. Some of them include the following.

  • Final
  • Static
  • Abstract
  • Interface
  • We use the ‘static’ keyword to make memory location constant.
  • However, there is the possibility to change the value held in the memory.
  • Even without creating an object, it is possible to access static members of a class.
  • Static members are called class members.

Static keywords are known either as a keyword or modifier.

Some Key Points of Static Keyword in Java:

  • The Static keyword is only used for the Data Members and Member functions.
Use case of static keyword with Data Members and Member Functions
  • All Static Members are first to execute.
  • However, do not use static keywords along with Classes and Constructors
  • Consequently, there are no STATIC classes in Java
Static Keyword in Java shows errors with classes or constructors.
  • If there is a body for the static keyword, it is known as Static Block. 

STATIC BLOCK – has the highest PRECEDENCE among all the declarations of the class. It means it executes first, even before the static keyword.

  • NON-STATIC members CANNOT be referenced from a STATIC context

  • All STATIC members CAN be referenced from NON-STATIC context

  • All NON-STATIC members participate in every instance of the class
  • In order to ACCESS NON-STATIC members from a STATIC CONTEXT – we require an OBJECT

  • Superclass ‘static’ method CAN be Overridden as ‘static’ ONLY

  • It is not possible to declare Abstract methods as ‘static’

  • It is possible to access all static members outside the class using its class name.
  • You can import packages statically

Leave a ReplyCancel reply

Discover more from BerylSoft

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version