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

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.No. Static Variable Final Variable
1 The static keyword is connected to occupied static classes, variables, methods and blocks. The final keyword is connected to class, variables and 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 methods can call them. They cannot be inherited.
5 The object of the static class cannot be created, and holds only static members. It is not possible to inherit the final class from any class.
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 along with GATE Eligibility CriteriaGATE 2024GATE Admit CardGATE Application FormGATE SyllabusGATE CutoffGATE Previous Year Question Paper, and more.

Also Explore,

Comments

Leave a Comment

Your Mobile number and Email id will not be published.

*

*