- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Initializer for final static field in Java
The final static field variable is a constant variable. There is only one copy of this variable available. It is mandatory to initialize the final static field variable explicitly as the default value for it is not provided by the JVM. Also, this variable cannot be reinitialized.
A program that initializes the final static field variable using a static initialization block is given as follows:
Example
public class Demo { final static int num; static { System.out.println("Running static initialization block."); num = 6; } public static void main(String[] args) { System.out.println("num = " + num); } }
Output
Running static initialization block. num = 6
Now let us understand the above program.
The class Demo contains the final static field variable num. The static initialization block initializes num. Then the value of num is printed in the main() method. A code snippet which demonstrates this is as follows:
final static int num; static { System.out.println("Running static initialization block."); num = 6; } public static void main (String [] args) { System.out.println ("num = " + num); }
- Related Articles
- Final static variables in Java
- Static and non static blank final variables in Java
- Difference Between Static and Final in Java
- What is static blank final variable in Java?
- What is blank final variable? What are Static blank final variables in Java?
- Assigning values to static final variables in java\n
- Reference static field after declaration in Java
- Can constructors be marked final, abstract or static in Java?
- instance initializer block in Java
- The Initializer Block in Java
- Interface variables are static and final by default in Java, Why?
- Can we declare an abstract method final or static in java?
- What is the equivalent of Java static final fields in Kotlin?
- Why use instance initializer block in Java?
- Why Java wouldn't allow initialization of static final variable in a constructor?

Advertisements