//Enumberation Fundamentals
// method
/*
*public static enum-type [] values();//returns an array
*public static enum-type valueof(String str);//returns enumeration constant
*/
enum Apple {
Jonathan, GoldenDel, RedDel, Winesap, Cortland
}
class EnumDemo {
public static void main(String args []) {
Apple ap;
ap= Apple.RedDel;
System.out.println("Value of ap: "+ ap);
System.out.println();
ap= Apple.GoldenDel;
if(ap == Apple.GoldenDel)
System.out.println("ap contains GoldenDel.\n");
//
switch(ap) {
case Jonathan:
System.out.println("Jonathan is red.");
break;
case GoldenDel:
System.out.println("Golden Delicious is yellow.");
break;
case RedDel:
System.out.println("reddel is red.");
case Winesap:
System.out.println("Winesap is red.");
case Cortland:
System.out.println("Cortland is red.");
}
Apple allapples[]= Apple.values();
for(Apple a: allapples)
System.out.println(a);
System.out.println();
ap= Apple.valueOf("Winesap");
System.out.println("ap contains "+ ap);
}
}
Enumeration基础
最新推荐文章于 2023-04-19 16:20:27 发布