-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEnumeration.java
More file actions
55 lines (38 loc) · 1.07 KB
/
Copy pathEnumeration.java
File metadata and controls
55 lines (38 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
enum Laptop{
Macbook, XPS, Thinkpad, Surface
}
//enum is a class but we can't extend it.
//enum in java extends enum class.
//We can create constructors and methods in enum.
//
//different depiction of enum class
enum Laptops{
Macbook(2000), XPS(1500), Thinkpad(1000);
private int price;
//we are having the constructor private because we are createing the objects inside the class.
private Laptops (int price){
this.price = price;
}
public int getPrice(){
return this.price;
}
public void setPrice(int price){
this.price = price;
}
}
public class Enumeration{
public static void main(String a[]){
Laptop lap = Laptop.XPS;
System.out.println(lap);
System.out.println("Here's the values of the enum : ");
Laptop lapis[] = Laptop.values();
for(Laptop l : lapis){
System.out.println("Type : " + l + " and ordinal is : " + l.ordinal());
}
//for the Laptops
Laptops laps[] = Laptops.values();
for( Laptops lapi : laps){
System.out.println("Laptop : " + lapi + " Price" + lapi.getPrice());
}
}
}