有的接口内只定义了常量,没有定义方法。继承了此类接口的类,可以直接使用这些常量。
public interface ConstantInterface {
String NAME = "RANGE";
int MAX = 100;
int MIN = 10;
}
public class ConstantInterfaceImpl implements ConstantInterface {
public static void main(String[] args) {
System.out.println(String.format("name: %s max: %d min: %d", ConstantInterface.NAME, ConstantInterface.MAX, ConstantInterface.MIN));
System.out.println(String.format("name: %s, max: %d, min: %d", NAME, MAX, MIN));
}
}