Advertisement



< Prev
Next >



Enums in Java





A Java Enumeration(Enums) defines a class type through which we can define a list of constants. By default, these constants are public, static and final.




Features of Enums







Creating a simple enumeration.


//Java - Enumeration example


enum Cities{ 
Frankfurt, NewYork, Sydney, Tokyo		//enumeration constants
}


class A
{
public static void main(String... ar)
{
	//Creating a variable of Enum type, Cities and initializing it to the enum constant, Sydney
	Cities c= Cities.Sydney;
	
	//Printing the value of Enum variable
	System.out.println(c);
}
}


Output is :


Sydney


Program Analysis


Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement



Notifications



Please check our latest addition

C#, PYTHON and DJANGO


Advertisement