Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to initialize blank final variable

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 347
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: