0

Can we declare a variable as static final and assign a value to it in the next line?

28th Jul 2016, 4:48 AM
Selva Kumar
Selva Kumar - avatar
2 Answers
+ 3
Yes, but you also need a static block. For example public class Program { static final String a; static { a = "a";} public static void main(String[] args) { System.out.println(a); } }
28th Jul 2016, 10:09 AM
WPimpong
WPimpong - avatar
+ 1
I stand corrected. learn something new everyday :)
28th Jul 2016, 10:46 AM
James
James - avatar