• Networking
  • Programming
  • DBMS
  • Operating System
  • Internet
  • Hardware
  • Software

Tech Differences

Know the Technical Differences

Difference Between Static and Final in Java

static-and-finalStatic and final both are the keywords used in Java. The static member can be accessed before the class object is created. Final has a different effect when applied to class, methods and variables.

The main difference between a static and final keyword is that static is keyword is used to define the class member that can be used independently of any object of that class. Final keyword is used to declare, a constant variable, a method which can not be overridden and a class that can not be inherited.

Content: Static Vs Final in Java

  1. Comparison Chart
  2. Definition
  3. Key Differences
  4. Conclusion

Comparison Chart

Basis for ComparisonStaticFinal
ApplicableStatic keyword is applicable to nested static class, variables, methods and block.Final keyword is applicable to class, methods and variables.
InitializationIt is not compulsory to initialize the static variable at the time of its declaration.It is compulsory to initialize the final variable at the time of its declaration.
ModificationThe static variable can be reinitialized.The final variable can not be reinitialized.
MethodsStatic methods can only access the static members of the class, and can only be called by other static methods.Final methods can not be inherited.
ClassStatic class's object can not be created, and it only contains static members only.A final class can not be inherited by any class.
BlockStatic block is used to initialize the static variables.Final keyword supports no such block.

Definition of Static

Static is a keyword, applicable to the classes, variables, methods, and blocks. The class members, class, and blocks can be made static using “static” keyword in front of the name of the class members, class, and blocks respectively. When a class member is declared as static, it becomes global for all other members of the class.

The static member of the class does not occupy memory on per instance basis, i.e. all the objects shares the same copy of static member. The static member can be used independently of any object of that class. You can access the static member of the class before its object is created. The best example of the static member is main( ) method, it is declared static so that it can be invoked before any object exists.

The general form to access the static member of the class:

class_name.static_member // accessing static member of the class

In above code class_name is the name of the class in which the static_member is defined. Static member can be a static variable or static method

Static variables

  • A static variable acts like a global variable for all other data members of the class.
  • A static variable can be accessed before any object of the class exists.
  • A static variable can be accessed with the class name in which it is defined followed by the dot(.) operator.

Static Methods

  • A static method can only call other static methods only.
  • A static method can access static data only.
  • A static method can not be referred to “this” or “super” in any conditions.
  • A static method can be accessed with the class name in which it is defined followed by the dot(.) operator.

Static class

  • Java does have the concept of nested static class. The outermost class can not be made static whereas the innermost class can be made static.
  • A static nested class can not access the non-static member of the outer class.
  • It can only access the static members of the outer class.

Static Block

Static block is executed only once when the class is loaded. Used to initialize the static variables of the class.

C++

In C++ we have the concept of static variables as well as static functions whereas, C++ do not support static class.

C#

C# supports static class, static variables, and static Class also.

Java

Java supports static nested class, static variables, static methods.

Definition of Final

Final is a keyword applicable to the class, variable and methods. The class, variable and the method is declared as final using the keyword “final” preceded by their name. Once a variable is declared as final; it can not be modified further in the program. A final variable must be initialized at the time declaration. Final variables do not occupy memory on per-instance basis. All the objects of the classes share the same copy of the final variable.

The method declared as final can not be overridden by the subclass of that class in which final method is declared. When a class is declared as final other class can not inherit that final class. C++, C# do not support the concept if final keyword. Java supports the concept of final keyword and in Java;  class, variable, and method can be declared as final.

Key Differences Between Static and Final in Java

  1. The static keyword  is applicable to a nested static class, variables, methods and blocks. On the other hand, final keyword is applicable to class methods and variables.
  2. Static variable can be initialized any time whereas, a final variable must be initialized at the time of declaration.
  3. A static variable can be reinitialized whereas, once initialized a final variable can never be reinitialized.
  4. A static method can access the static member of the class and can only be invoked by other static methods. On the other hand, the final method can never be inherited by any class.
  5. Static block is used to initialize the static variables whereas, final keyword does not support any block.

Conclusion

Both static and final keyword resolve different purpose when applied to class, variable, and method.

Related Differences:

  1. Difference Between Structure and Union
  2. Difference Between Interface and Abstract Class in Java & C#
  3. Difference Between throw and throws in Java
  4. Difference Between Structure and Class
  5. Difference Between Final, Finally and Finalize in Java

Comments

  1. Rohit says

    July 5, 2018 at 2:31 pm

    Please tell the difference between inner classes and subclasses.

    Reply
    • Neelima P says

      July 6, 2018 at 9:52 am

      We will update the difference soon. Keep viewing .. 🙂

      Reply
  2. vivek says

    July 29, 2018 at 5:25 am

    the info was very useful.

    Reply
  3. haynes christian says

    October 26, 2018 at 4:53 pm

    Can you tell me the difference between static, final and finalize.

    Reply
  4. A-aron says

    November 27, 2019 at 7:39 am

    Awesome comparison and contrast, thank you!

    Reply
  5. Prism says

    May 2, 2021 at 3:15 am

    Great Explanation, Everything covered in this article about static keyword… Great

    Reply
  6. Abhijit Zende says

    November 7, 2021 at 2:30 pm

    Can we make a class or method , final and static together at same time?

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Top 10 Differences

  • Difference Between OLTP and OLAP
  • Difference Between while and do-while Loop
  • Difference Between Guided and Unguided Media
  • Difference Between Preemptive and Non-Preemptive Scheduling in OS
  • Difference Between LAN, MAN and WAN
  • Difference Between if-else and switch
  • Difference Between dispose() and finalize() in C#
  • Difference Between for and while loop
  • Difference Between View and Materialized View
  • Difference Between Server-side Scripting and Client-side Scripting

Recent Addition

  • Difference Between Java and Python
  • Difference Between PHP and HTML
  • Difference Between GPS and GNSS 
  • Difference Between Virtualization and Containerization
  • Difference Between Storage and Memory

Categories

  • Artificial Intelligence
  • DBMS
  • Hardware
  • Internet
  • Networking
  • Operating System
  • Programming
  • Software

Copyright © 2025 · Tech Differences · Contact Us · About Us · Privacy