java enum
Java
public class MyClass {
enum Level {
LOW,
MEDIUM,
HIGH
}
public static void main(String[] args) {
Level myVar = Level.MEDIUM;
System.out.println(myVar);
}
}
public class DaysOfTheWeek {
public enum Days {m, t, w, r, f, sat, s};
public static void main(String[] args) {
Days d = Days.t;
System.out.println(d);
//the output would be t
}
}// A simple enum example where enum is declared
// outside any class (Note enum keyword instead of
// class keyword)
enum Color
{
RED, GREEN, BLUE;
}
public class Test
{
// Driver method
public static void main(String[] args)
{
Color c1 = Color.RED;
System.out.println(c1);
}
}
public enum Day {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
THURSDAY, FRIDAY, SATURDAY
}
// Java program to demonstrate that enums can have constructor
// and concrete methods.
// An enum (Note enum keyword inplace of class keyword)
enum Color
{
RED, GREEN, BLUE;
// enum constructor called separately for each
// constant
private Color()
{
System.out.println("Constructor called for : " +
this.toString());
}
public void colorInfo()
{
System.out.println("Universal Color");
}
}
public class Test
{
// Driver method
public static void main(String[] args)
{
Color c1 = Color.RED;
System.out.println(c1);
c1.colorInfo();
}
}
public class EnumTest {
Day day;
public EnumTest(Day day) {
this.day = day;
}
public void tellItLikeItIs() {
switch (day) {
case MONDAY:
System.out.println("Mondays are bad.");
break;
case FRIDAY:
System.out.println("Fridays are better.");
break;
case SATURDAY: case SUNDAY:
System.out.println("Weekends are best.");
break;
default:
System.out.println("Midweek days are so-so.");
break;
}
}
public static void main(String[] args) {
EnumTest firstDay = new EnumTest(Day.MONDAY);
firstDay.tellItLikeItIs();
EnumTest thirdDay = new EnumTest(Day.WEDNESDAY);
thirdDay.tellItLikeItIs();
EnumTest fifthDay = new EnumTest(Day.FRIDAY);
fifthDay.tellItLikeItIs();
EnumTest sixthDay = new EnumTest(Day.SATURDAY);
sixthDay.tellItLikeItIs();
EnumTest seventhDay = new EnumTest(Day.SUNDAY);
seventhDay.tellItLikeItIs();
}
}
Also in Java:
- Title
- init admob
- Category
- Java
- Title
- how to change double to int in java
- Category
- Java
- Title
- java print type of object
- Category
- Java
- Title
- What is returned by a producer.send() call in the Java API? A boolean indicating if the call succeeded Future object Future object Unit
- Category
- Java
- Title
- java calculator code
- Category
- Java
- Title
- java remove duplicates
- Category
- Java
- Title
- how to send http post create request using curl command
- Category
- Java
- Title
- Java create array of array
- Category
- Java
- Title
- java hashmap put
- Category
- Java
- Title
- number of matches regex java
- Category
- Java
- Title
- java make arraylist
- Category
- Java
- Title
- how take inputs in java with message
- Category
- Java
- Title
- shortcut to find a class in java project eclipse
- Category
- Java
- Title
- onbackpressed android
- Category
- Java
- Title
- remove part of string java
- Category
- Java
- Title
- 2d arrays | java
- Category
- Java
- Title
- caesar cipher java
- Category
- Java
- Title
- sqrt in java
- Category
- Java
- Title
- java hahmap
- Category
- Java
- Title
- java console write
- Category
- Java
- Title
- string remove last character
- Category
- Java
- Title
- value receive null with post method in the java spring controller
- Category
- Java
- Title
- Java system load from resources
- Category
- Java
- Title
- iterate map in java
- Category
- Java
- Title
- how to make a fixed size array in java
- Category
- Java
- Title
- NumSelfDivisors java
- Category
- Java
- Title
- how to add all list elements at once in java
- Category
- Java
- Title
- get current day java
- Category
- Java
- Title
- not equal to java
- Category
- Java
- Title
- Java.awt graphics tutorial
- Category
- Java
- Title
- java recursion
- Category
- Java
- Title
- java newinstance alternative
- Category
- Java
- Title
- split by new line java
- Category
- Java
- Title
- reading in lines from a file java
- Category
- Java
- Title
- java djikstra's algorithm
- Category
- Java
- Title
- java literals w3schools
- Category
- Java
- Title
- double round java integer
- Category
- Java
- Title
- java create circle
- Category
- Java
- Title
- jar file not running after being compiled
- Category
- Java
- Title
- java animated gif example
- Category
- Java
- Title
- java code to get all leaf nodes of a xml file
- Category
- Java
- Title
- java return new instance of generic type
- Category
- Java
- Title
- iterate through hashtable java
- Category
- Java
- Title
- adb: command not found
- Category
- Java
- Title
- java observable to observer stack overflow
- Category
- Java
- Title
- jframe border
- Category
- Java
- Title
- enum java
- Category
- Java
- Title
- generate random number java
- Category
- Java
- Title
- deleting elements of an array in java
- Category
- Java
- Title
- how do you concatenate an int with a string in java
- Category
- Java
- Title
- java square a number
- Category
- Java
- Title
- how to print the map in java
- Category
- Java
- Title
- sort a map based on keys and values using java 8
- Category
- Java
- Title
- java projects
- Category
- Java
- Title
- fastapi list query parameter
- Category
- Java
- Title
- primitive and non primitive data types in java
- Category
- Java
- Title
- javafx action event enter key
- Category
- Java
- Title
- java how to print a newline
- Category
- Java
- Title
- double to string java
- Category
- Java
- Title
- bukkit java get player count
- Category
- Java
- Title
- how to run java program in linux server
- Category
- Java
- Title
- setting up javafx in eclipse
- Category
- Java
- Title
- kotlin enable and disable parents view children
- Category
- Java
- Title
- primitive data types in java
- Category
- Java
- Title
- java read lines from file
- Category
- Java
- Title
- place.getlatlng() returning null
- Category
- Java
- Title
- java max
- Category
- Java
- Title
- how to fill a 2d array in java
- Category
- Java
- Title
- create jdbc connection in java
- Category
- Java
- Title
- java get last char of string
- Category
- Java
- Title
- java integer compareto
- Category
- Java
- Title
- init cap java
- Category
- Java
- Title
- parallel sorting in java 8
- Category
- Java
- Title
- get day name from date in java
- Category
- Java
- Title
- java new string with values
- Category
- Java
- Title
- how to take binary input in java
- Category
- Java
- Title
- Spigot API inventory close
- Category
- Java
- Title
- java script find screen size of device
- Category
- Java
- Title
- how to get all the names of the files in a folder in java?
- Category
- Java
- Title
- read and write files pattern java
- Category
- Java
- Title
- java get first char
- Category
- Java
- Title
- java 8 seconds to days
- Category
- Java
- Title
- how to pass parameters to xsl file
- Category
- Java
- Title
- lightweight java game library
- Category
- Java
- Title
- substring java
- Category
- Java
- Title
- usaco 2018 january contest
- Category
- Java
- Title
- how to copy list item to another list in java
- Category
- Java
- Title
- java final meaning
- Category
- Java
- Title
- linux command to see all the java version installed
- Category
- Java
- Title
- java length of matrix
- Category
- Java
- Title
- array in java
- Category
- Java
- Title
- calculating the percentile in java
- Category
- Java
- Title
- how to cut a certion part from a string in java
- Category
- Java
- Title
- how to format a datetime object to show date and time and milliseconds in java
- Category
- Java
- Title
- create an empty array in java
- Category
- Java
- Title
- D/NetworkSecurityConfig: No Network Security Config specified, using platform default
- Category
- Java
- Title
- java permutation
- Category
- Java
- Title
- stack overflow recyclerview
- Category
- Java
- Title
- Fab to CircularRevealFrameLayout example
- Category
- Java
- Title
- java fx display simple rectangle
- Category
- Java