Variables in Interfaces
We can use interface to organize constants.
interface MyConstants {
int NO = 0;
int YES = 1;
}
class Question implements MyConstants {
int ask() {
return YES;
}
}
public class Main implements MyConstants {
static void answer(int result) {
switch (result) {
case NO:
System.out.println("No");
break;
case YES:
System.out.println("Yes");
break;
}
}
public static void main(String args[]) {
Question q = new Question();
answer(q.ask());
}
}
The output:
Yes