[Java] Enum

Back-End/Java_1 2016. 5. 13. 11:27
donaricano-btn

Enum

- Enum constants are by default public static final fields. If you declare Enum is a member of your class, they by default it is static, We should not use new operator with enum type at anytime


1. Example


2. How to call Enums in class

If you declare Enum is a member of a class, then by default is is static. you can access it with reference to enclosing class


3. How to override toString() with enum

By default the enum toString() method returns the constant name itself. you can change return value by overriding toString() method


4. How to create custom constructor enum

The constructor should be either private or default scope, should not be protected or public. All elements defined in the enum must call constructor


'Back-End > Java_1' 카테고리의 다른 글

[Java] JDK, JRE, and JVM  (0) 2016.06.03
[Java] Exception  (0) 2016.05.18
[Java] Constructor  (0) 2016.05.17
[Java] Array  (0) 2016.05.12
[Java] Static  (0) 2016.05.11
블로그 이미지

리딩리드

,