Can an interface hold any instance variables? In my instructor's specs, it says no instance variables are allowed in interface. But I've researched and some say that it can only contain final
instance variable. If it can hold a final
instance variable, so what role can that variable play at all in an interface?

- 100,966
- 191
- 140
- 197

- 321
- 3
- 5
- 13
-
3No, any variable will be implicitly `public` `final` but also `static` which means it will not be instance variable, but class variable. – Pshemo Apr 16 '15 at 06:17
-
3Where have you found the information that an interface can hold instance variables? On Stackoverflow? Can you provide a link, please? – Tom Apr 16 '15 at 06:20
7 Answers
variables declared in interface are by default public
, static
and final
. Since it is static you cannot call it instance variable.

- 66,731
- 38
- 279
- 289
Variables which declared in interface are by default public, static and final.
These are static so you cannot call it as instance variable.

- 636
- 6
- 12
By default interface variables will always be public static final whether you mention these modifiers or not while defining variables. So, you can never have an instance variable in an interface.

- 1,526
- 5
- 26
- 42
Variables declared in an interface are by default public
, static
and final
by default. So you can use interfaces to define constants.
You can read more about this Here

- 891
- 9
- 27
Variable declared inside Interface are public, static, final(by default) making it not an instance variable for Interface.
Eg:
Interface abc{int a; // compiler will ask to assign value, since it is final}

- 23
- 2
- 5
At first we need to understand what is the role of interface. As such interface has by default abstract modifier.
1) So no object can be created for interface. As such object can not be created no role of instance variable in interface.
No object can be created for interface so no constructor supported for same.
2) Interface variables which declared are by default public, static and final and must need initialize at the time of declaration.
3) With Static you cannot call it as instance variable you can call it by.
interface_filename.interface_variablename
No interface cannot have instance variable.

- 163
- 1
- 7
Interface doesnt hold by itself instance variables of its own as by default inside interface variables are static and final. But can show the same purpose when implementing an interface as the interface object/instance is made is of class type.
It can be said as object referenced variables via interface.
class sample implements interfacee {
String xyz = "hello";
}

- 3,830
- 2
- 10
- 29