A SCJP question about Java enumerations
Given the following:
1.public enum Wallpaper {
2. BROWN, BLUE, YELLOW;
3.}
Which of the following are legal?
-
enum PatternedWallpaper extends Wallpaper { STRIPES, DOTS, PLAIN; } -
Wallpaper wp = Wallpaper.BLUE;
-
Wallpaper wp = new Wallpaper(Wallpaper.BLUE);
-
void aMethod(Wallpaper wp) { System.out.println(wp); } -
int hcode = Wallpaper.BLUE.hashCode();
Answer: only items 2, 4 and 6 are corrects. We can“t extend or instantiate an enumeration. The item 2 is the correct way to get a enumeration reference, the item 4 shows a method receiving a enumeration reference, and finally item 6 shows a call for the hashCode() method that all enums inherit from Object.




















July 1st, 2007 at 4:57 pm
hi,
answer 6 is not available ;-)
anyway - nice blog
marcel