CodesJava

Easy learning with example program codes

what is static blank final variable in java?


A static variable declared with final keyword but not initialised at declaration time is known as static blank final variable. It can be initialised in a static block only.

Example

/**
 * This class is used to show the example of static blank final variable.
 * @author CodesJava
 */
class Test{
	//blank final variable which can only be initialize 
	//through static initializer block.
	static final int num;
 
	static{
		num = 100;
		System.out.println("Num = " + num);
	}
}
public class FinalExample6 {
	public static void main(String args[]){
		new Test();
	}
}

Output

Num = 100

Java interview questions on final keyword



Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap