First example
public class MyClass { final int x = 2; }
x is
- final which means it can never be set after initialization.
- Initialized at declaration which means it can't have a different value assigned to it later (even in the constructor).
- fixed (regardless of the instance) because its value can't be changed in the constructor (or anywhere else really).
Second example
public class MyOtherClass { static final int x = 3; }
x is
- final which means it can never be set after initialization.
- Initialized at declaration which means it can't have a different value assigned to it later.
- a static field and the value will always remain the same regardless of the instance.
- constant because it is both static and final.
My questions are
What are the differences between both? (excluding creation time)
Am i missing something?