Java-Enumeration Super Class

Enumeration Super Class All enumerations automatically inherit java.lang.Enum. The Enum class defines several methods such as ordinal( ), compareTo( ), equals( ) and so on, that are available for use by all enumerations. You can obtain a value that indicates an enumeration constant’s position in the list of constants. This is called its ‘ordinal value’ and … Read more…

Java-Enumeration Class Types(Another Example)

Enumeration Class Types In the following program, the version of Fruits adds three things. The first is the instance variable rate, which is used to hold the rate of each variety of fruits. The second is the Fruits constructor, which is passed the rate of an fruit. The third is the method getRate( ), which … Read more…

Java-Enumeration Methods

Enumeration Methods All enumerations automatically contain two predefined methods values( ) and valueOf( ). The values( ) method returns an array that contains a list of the enumeration constants. The valueOf( ) method returns the enumeration content whose value corresponding to the string passed to it. The following program demonstrates the values( ) and valueOf( … Read more…

Java-Switch with Enumeration

Switch with Enumeration An enumeration value can also be used to control a switch statement. Of course, all of the case statements must use constants from the same enum as that used by the switch expression. For example, in the following program, notice that in the case statements, the names of the enumeration constants are used without being … Read more…

Java-Enumeration

Enumeration In its simplest form, an enumeration is a list of named constants. An enumeration is created using the enum keyword. For example, here is a simple enumeration that lists various Fruits varieties : The identifiers ‘Apple’, ‘Banana’, and so on, are called enumeration constants. Once you have defined an enumeration, you can create a … Read more…