Return to site

JAVA CERTIFICATION QUESTION: Enums and implementing interfaces in Java

· java

Even though an enum cannot use or be the target of an extends clause,

it is possible—in specific and limited situations—to have an enum that is a subclass of another enum.

Given an interface and two enums:

interface Emoticonable {
  public String getIcon();
}
enum Mood implements Emoticonable {
  GOOD { public String getIcon() { return ";-)"; } },
  BAD { public String getIcon() { return ";-("; } };
  public String toString() { return getIcon(); }
}
enum Emotion implements Emoticonable {
  LAUGHING { public String toString() { return getIcon(); }}, 
  CRYING { public String getIcon() { return ";'-("; } }
  public String getIcon() { return ";-|"; }
}

 

Which is true? Choose one.

A. Both enum types fail to compile.

B. The Emotion enum fails to compile.

C. The output is the following:

Good mood, laughing ;-) ;-|

D. The output is the following:

Good mood, laughing GOOD LAUGHING

 

 

 

·ꓛ uoᴉʇdo sᴉ ɹǝʍsuɐ ʇɔǝɹɹoɔ ǝɥꓕ ·uoᴉsnʅɔuoꓛ