enum in java
package govind;
public enum Beer
{
KF,RC,KO,FO;
}
package govind;
public class Test {
public static void main(String[] args) {
Beer b=Beer.KF;
System.out.println(b);
}
}
o/p:--------------------------------------------
KF
============================================================================================================================================
package govind;
public enum Beer
{
KF,RC,KO,FO;
}
package govind;
public class Test {
public static void main(String[] args) {
Beer b=Beer.KF;
switch (b) {
case KF:
System.out.println("it is children's brand");
break;
case KO:
System.out.println("it's too light");
break;
case FO:
System.out.println("bye one get one free");
break;
case RC:
System.out.println("it is not that much kick");
break;
/*case IB:
System.out.println("I m error because i m not define inside enum ");
break;*/
default:
System.out.println("other brans are not recommended");
break;
}
}
}
o/p:----------------------
it is children's brand
=========================================================================================================================================
package govind;
public enum Beer
{
KF,RC,KO,FO;
}
package govind;
public class Test {
public static void main(String[] args) {
Beer[] b = Beer.values();
for(Beer b1:b)
{
System.out.println(b1+"......."+b1.ordinal());
}
}
}
o/p:--------------------------------------------
KF.......0
RC.......1
KO.......2
FO.......3
No comments:
Post a Comment