0% found this document useful (0 votes)
5 views1 page

Understanding Static Keyword in Java

The document discusses the use of the static keyword in Java, which is essential for memory management and allows sharing of variables and methods across class instances. It covers static variables, which are shared among all objects of a class, and static methods, which are commonly used for the main method. The article highlights the significance of static in defining constants and managing class-level data.

Uploaded by

alvahitha2000
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Understanding Static Keyword in Java

The document discusses the use of the static keyword in Java, which is essential for memory management and allows sharing of variables and methods across class instances. It covers static variables, which are shared among all objects of a class, and static methods, which are commonly used for the main method. The article highlights the significance of static in defining constants and managing class-level data.

Uploaded by

alvahitha2000
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Use of Static Keyword in Java

In Java, keywords are the reserved words that cannot be used as identifiers. One among them is
“Static“.

Below topics are covered in this article:

Introduction to Static keyword in Java

Applications of Static keyword

Static Variable

Static Method

Static Classes

Introduction to Static Keyword in Java

In Java, static keyword is mainly used for memory management. It can be used with variables,
methods, blocks and nested classes. It is a keyword which is used to share the same variable or
method of a given class. Basically, static is used for a constant variable or a method that is same
for every instance of a class. The main method of a class is generally labeled static.

Static Variable

When you declare a variable as static, then a single copy of the variable is created and divided
among all objects at the class level. Static variables are, essentially, global variables. Basically,
all the instances of the class share the same static variable. Static variables can be created at
class-level only.

Static Methods

When a method is declared with the static keyword, it is known as a static method. The most
common example of a static method is the main( ) method. Methods declared as static can
have the following restrictions:

You might also like