What is the output from the following code
interface Choices { int YES = 1; int NO = 2; } public class Main { public static void main(String[] args) { System.out.println("Choices.YES = " + Choices.YES); System.out.println("Choices.NO = " + Choices.NO); Choices.NO = 9; System.out.println("Choices.NO = " + Choices.NO); } }
Choices.NO = 9; // A compile-time error
Fields in an interface are final whether the keyword final is used in its declaration or not.
You must initialize a field at the time of declaration.
A final field is assigned a value only once, you cannot set the value of the field of an interface, except in its declaration.
The following snippet of code shows some valid and invalid field declarations for an interface: