Skip to content

Instantly share code, notes, and snippets.

@ajduke
Created April 1, 2012 03:31
Show Gist options
  • Save ajduke/2270978 to your computer and use it in GitHub Desktop.
Save ajduke/2270978 to your computer and use it in GitHub Desktop.
Initializing Final variables
package ajd.examples.basics;
public class FinalVariable {
final int finalInstanceField
// =5
;
static final int finalStaticField = 5;
{
// finalField = 5;
}
static {
// finalStaticField = 7;
}
public FinalVariable() {
finalInstanceField = 7;
// finalStaticField=5;
}
public static void main(String[] args) {
final int a = 0 ;
System.out.println(a);
System.out.println(finalStaticField);
System.out.println(new FinalVariable().finalInstanceField);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment