package com.Lucky.OftenClass; /* 枚举定义 */ public enum EnumClass { //枚举内容 男,女,girl,boy }
package com.Lucky.OftenClass; public class testEnum { private String name; private EnumClass age; public testEnum() { } public testEnum(String name, EnumClass age) { this .name = name; this .age = age; } public String getName() { return name; } public void setName(String name) { this .name = name; } public EnumClass getAge() { return age; } public void setAge(EnumClass age) { this .age = age; } @Override public String toString() { return "testEnum{" + "name='" + name + '\ '' + ", age=" + age + '}' ; } ////使用枚举 public static void main(String[] args) { testEnum num = new testEnum(); num.name= "唯易人生" ; //num.age="erdfgn"; //约束输入的内容 num.age=EnumClass.girl; //使用枚举赋值 System.out.println(num); } }
标签:常用,testEnum,java,name,age,枚举,EnumClass,public,String From: https://www.cnblogs.com/Lucky-only/p/16922190.html