Sitemap
Thayana Selvaratnam

Thayana Selvaratnam

Full stack web developer | Angular, Spring boot, my sql | A third year undergraduate of Faculty of Information Technology, University of Moratuwa.

Press enter or click to view image in full size

Enum Data Type in Java

2 min readMay 3, 2020

An ‘enum’ is a special “class” in java. This class available in java.lang package. Enumerated data types are used to represent a group of named constants in Java.

To create an enum, use the ‘enum’ keyword, separate the constants with a comma, and they should be in uppercase letters.

For Example 1 :-

enum Animal{ CAT, DOG, ELEPHANT }

Example 2:-

enum Day{ SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }

Get Thayana Selvaratnam’s stories in your inbox

Join Medium for free to get updates from this writer.

NODE :- enum data types can be declared outside a Class or inside a Class but not inside a Method, and also we can declare main() method inside enum.

  1. Declared outside a Class
Press enter or click to view image in full size

2. Defined inside the class

Press enter or click to view image in full size

3. Declare main() method inside enum

Press enter or click to view image in full size

Thank you.

--

--

Thayana Selvaratnam
Thayana Selvaratnam

Written by Thayana Selvaratnam

Full stack web developer | Angular, Spring boot, my sql | A third year undergraduate of Faculty of Information Technology, University of Moratuwa.