Days.java
public enum Days
{
Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday
};
Test.java
public class Test
{
public static void main(String []args)
{
Days d;
Days enumarr[]=Days.values();
for(Days x:enumarr)
{
System.out.print(x.ordinal()); // it should print the constant value
System.out.print(" "+x); // it should print all the days
System.out.print("\n");
}
System.out.println("Printing using Valueof()");
System.out.println(Days.valueOf("Friday")); //it should print Friday
}
}
0 comments:
Post a Comment