Pin It

Program to demonstrate how a simple Enum works in Java ?

A Simple Java program demonstrating how a simple Enum works in Java :

package com.hubberspot.objects.example;

enum IplTeams {
        DeccanChargers, KolkataNightRiders, 
 MumbaiIndians, ChennaiSuperKings, 
 RajasthanRoyals, RoyalChallengersBangalore,
 KingsXIPunjab, PuneWarriorsIndia,
 DelhiDaredevils
};

public class SimpleEnumDemo {
  public static void main(String[] args) {
    IplTeams team1 = IplTeams.MumbaiIndians;
    IplTeams team2 = IplTeams.DeccanChargers;
    IplTeams team3 = IplTeams.KolkataNightRiders;
    IplTeams team4 = IplTeams.ChennaiSuperKings;
    IplTeams team5 = IplTeams.RajasthanRoyals;
    IplTeams team6 = IplTeams.RoyalChallengersBangalore;
    IplTeams team7 = IplTeams.KingsXIPunjab;
    IplTeams team8 = IplTeams.PuneWarriorsIndia;
    IplTeams team9 = IplTeams.DelhiDaredevils;
    
    System.out.println("This Season's IPL teams are :");
    System.out.println("1. "+team1);
    System.out.println("2. "+team2);
    System.out.println("3. "+team3);
    System.out.println("4. "+team4);
    System.out.println("5. "+team5);
    System.out.println("6. "+team6);
    System.out.println("7. "+team7);
    System.out.println("8. "+team8);
    System.out.println("9. "+team9);
  }
}


Output of the program :





Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot