-
Notifications
You must be signed in to change notification settings - Fork 0
/
Example.java
40 lines (35 loc) · 1.22 KB
/
Example.java
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
package com.trl.theoreticalKnowledge._enum.methods.a.a3;
public class Example {
public static void main(String[] args) {
// Color.WHITE.doSomething(); // Compilation ERROR !!! Cannot resolve method 'doSomething' in 'Color'.
// Color.BLACK.doSomething(); // Compilation ERROR !!! Cannot resolve method 'doSomething' in 'Color'.
// Color.RED.doSomething(); // Compilation ERROR !!! Cannot resolve method 'doSomething' in 'Color'.
// Color.YELLOW.doSomething(); // Compilation ERROR !!! Cannot resolve method 'doSomething' in 'Color'.
}
}
enum Color {
WHITE {
public void doSomething() {
System.out.println("WHITE");
}
},
BLACK {
public void doSomething() {
System.out.println("BLACK");
}
},
RED {
public void doSomething() {
System.out.println("RED");
}
},
YELLOW {
public void doSomething() {
System.out.println("YELLOW");
}
};
// Is mandatory definition of this method if you want to use method "doSomething()".
// public void doSomething() {
// System.out.println("default value");
// }
}