- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Blank final in Java
In Java, a final variable can a be assigned only once. It can be assigned during declaration or at a later stage. A final variable if not assigned any value is treated as a blank final variable. Following are the rules governing initialization of a blank final variable.
A blank instance level final variable cannot be left uninitialized.
The blank Instance level final variable must be initialized in each constructor.
The blank Instance level final variable cannot be initialized in class methods.
A blank static final variable cannot be left uninitialized.
The static final variable must be initialized in a static block.
A static final variable cannot be initialized in constructor or class methods.
Example
public class Tester { public final int a; public static final int b; static { b = 2; } Tester() { this(1); } Tester( int a) { this.a = a; } public static void main(String[] args) { Tester tester = new Tester(); System.out.println("a = " + tester.a + ", b = " + b); } }
Output
a = 1, b = 2
- Related Articles
- What is blank final variable? What are Static blank final variables in Java?
- What is static blank final variable in Java?
- Can we initialize blank final variable in Java
- What is a blank uninitialized final variable in java?
- What is blank or uninitialized final variable in Java?
- Static and non static blank final variables in Java
- Why should a blank final variable be explicitly initialized in all Java constructors?
- Assigning values to static final variables in java\n
- final keyword in Java
- Final variable in Java
- Final class in Java
- Final Arrays in Java
- final variables in Java
- Is StringBuffer final in Java?
- final local variable in Java

Advertisements