- 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
What is a blank uninitialized final variable in java?
A final variable can be explicitly initialized only once. A reference variable declared final can never be reassigned to refer to a different object. However, the data within the object can be changed. So, the state of the object can be changed but not the reference. With variables, the final modifier often is used with static to make the constant a class variable.
Therefore, once we declare a final variable it is mandatory to initialize the final variable at the time of declaration or using constructor.
If not, a compile time error may occur saying “The blank final field num may not have been initialized”.
Example
public class Test{ final int num; public static void main(String args[]){ Test t = new Test(); System.out.println(t.num); } }
Error
C:\Sample>javac Test.java Test.java:2: error: variable num not initialized in the default constructor final int num; ^ 1 error
- Related Articles
- What is blank or uninitialized final variable in Java?
- 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 final variable in java?
- Why should a blank final variable be explicitly initialized in all Java constructors?
- Blank final in Java\n
- Final variable in Java
- final local variable in Java
- Instance variable as final in Java
- Static and non static blank final variables in Java
- Unreachable statement using final variable in Java
- How to use a final or effectively final variable in lambda expression in Java?
- What is a final method in Java?
- What is a final parameter in java?

Advertisements