Search Interview Questions | Click here and help us by providing the answer. Click Correct / Improve and please let us know. |
|
|||
|
| ||||
| Core Java - Interview Questions and Answers for 'Enumeration' - 5 question(s) found - Order By Newest | ||||
| ||||
| Ans. No. compareTo method is declared final for the Enumerations and hence cannot be overriden. This has been intentionally done so that one cannot temper with the sorting order on the Enumeration which is the order in which Enum constants are declared. | ||||
| ||||
| Ans. An enumeration is an interface containing methods for accessing the underlying data structure from which the enumeration is obtained. It allows sequential access to all the elements stored in the collection. | ||||
| Ans. Enum is actually a class with pre defined constants. So enum name should follow the convention of the Class name. Though the constant names or the Enum variables should follow the convention of having all capital letters. | ||||
| ||||
| Ans. Yes, with Enum as was getting an exception while doing equality check for enum field. got it fixed by adding @Enumerated(EnumType.STRING) to the field in entity. | ||||
| ||||
| Ans. Enumeration can iterate only legacy collections like Vector , HashTable and Stack whereas Iterator can iterate both legacy and non legacy collections. Enumeration is less safer than Iterator Enumeration is fail safe whereas Iterator is fail fast Iterator allows for removal of element while traversal whereas Enumeration doesn't have remove method. Enumerations were introduced in Java 1 whereas Iterators were introduced with Java 2 Enumerations have methods like hasMoreElements and nextElement whereas Iterators have methods like hasNext, next and remove | ||||