We always write:
public static final int A = 0;
Question:
- Is
static finalthe only way to declare a constant in a class? - If I write
public final int A = 0;instead, isAstill a constant or just an instance field? - What is an instance variable? What’s the difference between an instance variable and an instance field?
enumtype in Java 5 and onwards for the purpose you have described. It is type safe.If you are talking about the difference between instance variable and class variable, instance variable exist per object created. While class variable has only one copy per class loader regardless of the number of objects created.
Java 5 and up
enumtypeIf you wish to change the value of the enum you have created, provide a mutator method.
Example of accessing: