0
Is it necessary for interface variables to be static or final?
2 ответов
+ 3
If you declare a variable in an interface like this:
public interface A {
int a = 4;
}
Then "a" will be implicitly public, static and final. So it is valid:
int i = A.a;
But it isn't:
A.a = 3;
+ 1
static variables must be initialized first, before other variables
final variables can be initialized in the constructor or in the object methods
both exist only one per class
static ones belong to the class, and don't need an intantiated object