Monday, February 2, 2009

Simple Java Program to understand enum basics

/*
------------------------------------------------------------------------
Simple Java Program to understand enum basics
------------------------------------------------------------------------
*/
enum Cars{ESCORT,FIAT,ALTO,ZEN}
class EnumExample{

public static void main(String args[]){

Cars oldest = Cars.FIAT;
System.out.println(oldest);

for(Cars c :Cars.values())
System.out.println(c);
}
}
/*
------------------------------------------------------------------------
Output of enum example
------------------------------------------------------------------------
C:\Users\flower\Documents\javaprogs>javac EnumExample.java

C:\Users\flower\Documents\javaprogs>java EnumExample
FIAT
ESCORT
FIAT
ALTO
ZEN

*/

No comments: