1.接口定义

public interface Constants1 {
    public String NAME = "nihao";
    public String HOBBY = "basketball";
    public Integer AGE = 15;
}
public class Test1 {
    public static void main(String[] args) {
        String name = Constants1.NAME;
        System.out.println(name);
    }
}

2.内部类定义

public class Constants2 {
    public class Teacher{
        public static final String COLUMN_NAME = "TL";
        public static final String COLUMN_CLASS = "3";
    }
    public class Student{
        public static final String COLUMN_NAME = "XM";
        public static final String COLUMN_TEACHER = "Z";
    }
    public class Father {
        public static final String COLUMN_NAME = "ZS";
    }
}
public class Test1 {
    public static void main(String[] args) {
        String columnName = Constants2.Student.COLUMN_NAME;
        System.out.println(columnName);
    }
}

3.枚举

public enum Color {
    BLACK("黑色",1),RED("红色",2),YELLO("黄色",3);
    private String name;
    private int num;
    Color(String name, int num) {
        this.name = name;
        this.num = num;
    }
    public String getName(){
        return name;
    }
    public int getNum(){
        return num;
    }
}
public class Test1 {
    public static void main(String[] args) {
        String name = Color.BLACK.getName();
        int num = Color.BLACK.getNum();
       System.out.println(String.format("name:%s,num:%s",name,num));
    }
}