Monday, October 1, 2012

Java Tidbits ............................4(enum)

  • Enums are special classes whose fields are constants.
  • Enum can be declared either inside of a class or as separate class.
  • When outside a class Enum can either be public or default access modifier. By default nested enum are static ( ie inside class ).
  • In Enum definitions the enum constants must be declared before any other declarations in an enum type. ( compile error will be thrown if it is occurs )
  • Enum cannot be declared inside methods .why ? ( because methods cannot have class ) 
  • ; colon is optional to be placed at end of enum syntax.
  • Enum cannot be invoked via new operator .
  • Like classes Enum can have multiple argument constructor or may have overloaded constructors  .
  • Like classes Enum can have methods definitions.
  • Enum can  provide constant specific class body ie : a particular constant can override one or more  of its methods .
  • Enum are implicitly Serialiazable and comparable and extends Enum abstract class , so enum can be  serialized and can be put into  ordered collection.
  • If there is any abstract method declared inside enum class then each of its enum type must have to provide its definition.
  • Abstract & Final Enum cannot be defined.
  • equals(), compareTo(), finalize() methods are final . it cannot be overridden.
  • Enum can implement interfaces but cannot extends any other class. 
  • Enum cannot be of Generic Type.
Practice few Enum from K & B book .

http://www.ejavaguru.com/scjp5freemockexam.php#enumq9

No comments: