Tuesday 9 May 2017

Java Tutorial: Enum in java[How to define a constructor and method in enum - Car]


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

EnumDemo.java
enum Car
{
    TATA(2), 
    AUDI(60), 
    FIAT(20), 
    HONDA(15);

    private int price;

    Car(int price)
    {
        this.price = price;
    }

    int getPrice()
    {
        return price;
    }
}

public class EnumDemo
{
    public static void main(String args[])
    {
        Car[] carArray = Car.values();
        System.out.println("All car prices:");
        for (Car car : carArray)
        {
            System.out.println(car + " costs " + car.getPrice()
                    + " thousand dollars.");
        }

    }
}
Output
All car prices:
TATA costs 2 thousand dollars.
AUDI costs 60 thousand dollars.
FIAT costs 20 thousand dollars.
HONDA costs 15 thousand dollars.
Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/EnumDemo_Car_Cons_method_App.zip?attredirects=0&d=1

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/45d5519a1474198166ac515ccd559cc996bb550c/BasicJava/EnumDemo_Car_Cons_method_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