0% found this document useful (0 votes)
2 views

Difference between Static and Final Variable in Java

The document explains the differences between static and final variables in Java, highlighting that static variables belong to the class and can be reinitialized, while final variables are constants that must be initialized at declaration and cannot be changed. It details the characteristics and limitations of both keywords, emphasizing their roles in object-oriented programming. The content serves as a guide for understanding these fundamental concepts in Java.

Uploaded by

syedirteza7860
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Difference between Static and Final Variable in Java

The document explains the differences between static and final variables in Java, highlighting that static variables belong to the class and can be reinitialized, while final variables are constants that must be initialized at declaration and cannot be changed. It details the characteristics and limitations of both keywords, emphasizing their roles in object-oriented programming. The content serves as a guide for understanding these fundamental concepts in Java.

Uploaded by

syedirteza7860
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

1/8/25, 11:01 PM Difference between Static and Final Variable in Java

Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests - Download the BYJU'S Exam Prep App fo

DOWNLOAD NOW (http://bit.ly/3i8IueA) ×

BYJU'S GATE (/gate/) > GATE (/gate/gate-exam/) > Difference Between (/gate/difference-between-in-gate/) > Difference Between Static and Final Variable in Java (/gate/difference-
between-static-and-final-variable-in-java/)

(tel:+919241333666)

Difference between Static and Final Variable in Java

Static and final are two important keywords that belong to object-oriented programming languages like Java. The static keyword is used to
represent the class member. It is basically used with methods and variables to indicate that it is a part of the class, not the object. On the other
hand, the final keyword is used to proclaim a constant variable and to bind the user from accessing a method, variable, or class. Let’s figure out
some major differences between static and final keywords in Java.

What is Static Variable in Java?


A variable with the static keyword is known as a static variable in Java. These variables are generally referred to as the common belongings of a
group of objects. These variables help in saving a lot of memory and getting the memory at the time of loading the class.

What is Final Variable in Java?


When a variable is expressed with the final keyword, then it is not possible to change its value. Yes, in Java, we can use the final keyword with
methods, variables and classes. When the final keyword is utilised with a variable of primitive data types, we cannot modify the value.

Difference between Static and Final Variable in Java

S.N Static Variable Final Variable


o.

1 The static keyword is connected to occupied static classes, variables, The final keyword is connected to class, variables and
methods and blocks. methods.

2 Here, it is not mandatory to initialise the static variable while declaring it.. Here, it is mandatory to initialise the final variable while
declaring it.

3 They can be reinitialized. We can not reinitialize the final keyword.

4 They can only access the static members of the class, and only static They cannot be inherited.
methods can call them.

5 The object of the static class cannot be created, and holds only static It is not possible to inherit the final class from any class.
members.

6 Static block is used to initialise the static variables. Final keyword does not support such a block.

Keep learning and stay tuned to BYJU’S to get the latest updates on GATE Exam (https://byjus.com/gate/gate-exam/) along with GATE Eligibility
Criteria (https://byjus.com/gate/gate-eligibility-criteria/), GATE 2024 (https://byjus.com/gate/), GATE Admit Card (https://byjus.com/gate/gate-
admit-card/), GATE Application Form (https://byjus.com/gate/gate-application-form/), GATE Syllabus (https://byjus.com/gate/gate-
syllabus/), GATE Cutoff (https://byjus.com/gate/gate-cutoff/), GATE Previous Year Question Paper (https://byjus.com/gate/previous-year-
question-papers/), and more.

https://byjus.com/gate/difference-between-static-and-final-variable-in-java/ 1/7

You might also like