Home > DeveloperSection > Interviews > Can we intialize blank final variable in java?

Posted on    April-01-2015 12:43 AM

 Java Java 
Ratings:
 1 Answer(s)
  362  View(s)
Rate this:

Mayank Tripathi
Mayank Tripathi

Total Post:807

Points:4035
Posted on    April-01-2015 1:20 AM

Yes, but only in constructor. For example:

  1. class Bike10{  
  1.   final int speedlimit;//blank final variable  
  1.     
  1.   Bike10(){  
  1.   speedlimit=70;  
  1.   System.out.println(speedlimit);  
  1.   }  
  1.   
  1.   public static void main(String args[]){  
  1.     new Bike10();  
  1.  }  

  1. Output:70

Don't want to miss updates? Please click the below button!

Follow MindStick