hi, i am very new to java want know wat is enumeration.... according to me enueration creates an oblect and stores all the values in the object one by one.... can someone explain and give some examples
There two different meanings for "enumeration" in Java.
First, there's interface java.util.Enumeration. You can use an Enumeration to walk through a collection of objects, to look at those objects one by one. Note that Enumeration is an old, legacy interface: it has been largely replaced by interface Iterator since Java 1.2.
Another meaning is enum types. [ January 09, 2008: Message edited by: Jesper Young ]
Enums allow you to make a list of values, like an array and these can be assigned to a variable. The order the values are listed is taken into account, just as they are in an array. The values are constants and should be in capital letters. You can treat the values in enums like objects and assign instance variables to each of those objects.
Here is an example that I�ve customized myself from an example in the SCJP Exam Study Guide (Page 63 & 64). I�ve looked into this subject and taken the code to pieces to try and understand the subject myself. I�ve also made the code a little more complicated than it is in the book. I�m currently studying for the exam.
Save this in a file called Engines.java in your java directory: