Blank final variables are those variables that are final but havent initialized at the time of declaration.
So its not possible to initialize it anywhere. Here is the solution.
We can initialize blank final variable only in the constructor.
Example:
Claspre Employee{
final int workingHour;
Employee(){
workingHour = 9;
System.out.println(Working hours : : + workingHour);
}
}
static blank final variable
static final variables are those variables that are not initialized at the time of declaration.
So if we want to initialize it we need to initialize it in static block only.
class Employee{
static final int workingHours;
static{
workingHours =50;
}
public static void main(String args[]){
System.out.println(Working hours : : +Employee.workingHours);
}
}
0 Comment(s)