Click here to watch in Youtube :
https://www.youtube.com/watch?v=leD-M96tdjU&list=UUhwKlOVR041tngjerWxVccw
EnumDemo.java
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.");
}
}
}
OutputAll 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:
No comments:
Post a Comment