Variable in Interface
Author: Ravi Poswal
When a variable is declare inside of the interface, it can be public, static and final. this is always conatin constant value (Fixed value)
Code Example
interface Bank {
double acc = 7.5;
}
class PNB implements Bank {
public static void main(String[] args)
{
System.out.println("Account balance: " + Bank.acc);
}
}
FAQs
A variable in an interface is a constant that is automatically public, static, and final.
No, because they are final (constant).
Yes, they must be initialized at the time of declaration.
InterfaceName.variableName
Because they belong to the interface, not to objects.
No, all variables are public by default.
It will give a compile-time error.
RANREV INFOTECH