Junior — Middle
Is it possible to define a non-static data member inside an interface in a programming language?
sobes.tech AI
Answer from AI
In Java, interfaces cannot contain non-static fields. All fields declared in an interface are, by default, public static final — that is, constants. This means that you cannot define a regular (non-static) field inside an interface.
If you need to store state, you typically use abstract classes or classes with implementations.
Example:
public interface MyInterface {
int CONSTANT = 10; // public static final by default
// int data; // cannot declare like this
}