0% found this document useful (0 votes)
2 views1 page

Enum Example Java Core

The document contains a Java program that demonstrates the use of enums for days of the week and cardinal directions. It defines two enums, 'Day' and 'Directions', with 'Directions' having a method to retrieve direction codes. The main method includes a switch statement for days and prints the direction code for 'SOUTH'.

Uploaded by

vijaya2511
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Enum Example Java Core

The document contains a Java program that demonstrates the use of enums for days of the week and cardinal directions. It defines two enums, 'Day' and 'Directions', with 'Directions' having a method to retrieve direction codes. The main method includes a switch statement for days and prints the direction code for 'SOUTH'.

Uploaded by

vijaya2511
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

package enumexamplefeb16;

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

enum Directions{ EAST ("E"), WEST ("W"), NORTH ("N"), SOUTH ("S") ;
private final String mydirection;
private Directions(String dd)
{
this.mydirection=dd;
}
public String getDirectionCode() {
return this.mydirection;
}
}
public class EnumExampleFeb16 {

public static void main(String[] args)


{

Day day=Day.MONDAY;

switch(day){
case SUNDAY:
System.out.println("sunday");
break;
case MONDAY:
System.out.println("monday");
break;
default:
System.out.println("other day");
}
Directions d1 = Directions.SOUTH;
System.out.println(d1.getDirectionCode());

You might also like