Free Data Structures and Algorithms Course









Subscribe below and get all best seller courses for free !!!










OR



Subscribe to all free courses

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 :





 
© 2021 Learn Java by Examples Template by Hubberspot