在Java中,常量可以使用以下几种方式来定义:
final int MAX_VALUE = 100;
public class Constants {
public static final int MAX_VALUE = 100;
}
public interface Constants {
int MAX_VALUE = 100;
}
public enum Constants {
MAX_VALUE(100);
private final int value;
private Constants(int value) {
this.value = value;
}
public int getValue() {
return this.value;
}
}