Posts

Showing posts from March, 2016

enums in Java

We can use enum to define a group of named constants. By using enum we can define our own data types. enum concept introduced in 1.5v. Java's enum are more powerful than enum in other languages. Declaration enum enum concept is internally implemented using class concept. Syntax of enum declaration are almost same as class declaration. enum keyword is used for declaring enums. //EXAMPLE CODE-1 public enum Month{ JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC; } In above example, We have declared Month as enum and JAN, FEB, MAR ...DEC are constants of type Month. A enum can have instance variables, method and constructor. Instance variables, method and constructor must be declared after enum constants declaration. If there are parameterised constructors in enum then enum constant must have these parameters. //EXAMPLE CODE-2 public enum Day { SUN("Sunday"), MON("Monday"), TUE("Tuesday"), WED("Wednesday"), THU(&quo