Tuesday, 9 May 2017

Java Tutorial: Enum in java | Java enum [How to use enum in a switch statement - Car]


Click here to watch in Youtube :
https://www.youtube.com/watch?v=_NBFtrNBmWY&list=UUhwKlOVR041tngjerWxVccw

EnumDemo.java
/*
 * How to use enum & switch statement?
 */
enum Car
{
    TATA, AUDI, FIAT, HONDA
}

public class EnumDemo
{
    public static void main(String args[])
    {
        Car car;
        car = Car.AUDI;
        switch (car)
        {
        case TATA:
            System.out.println("You choose tata!");
            break;
        case AUDI:
            System.out.println("You choose audi!");
            break;
        case FIAT:
            System.out.println("You choose fiat!");
            break;
        case HONDA:
            System.out.println("You choose honda!");
            break;
        default:
            System.out.println("I don't know your car.");
            break;
        }

    }
}
Output
You choose audi!
Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/EnumDemo_Car_switch_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/EnumDemo_Car_switch_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/45d5519a1474198166ac515ccd559cc996bb550c/BasicJava/EnumDemo_Car_switch_App/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge