- In the first case, you can use the
final class, since they cannot be inherited. - For your second case, you can use
interface , they are very well used for storing Constants .
But you cannot have both of them together (since having an interface that cannot be implemented does not make sense) ..
So, best of all, you can mix the property as in one class. You may have a final class variable with public static final , since this is what the constant variable in the interface does, will serve the purpose of Constants ..
public final class A { public static final int YOUR_CONST = 5; }
If you do not want to instantiate this class, you can have a private 0-arg constructor in it.
public final class A { public static final int YOUR_CONST = 5; private A() {} }
source share