What is the output of the following code?
enum Browser {//w ww. j a v a2 s . c o m FIREFOX("firefox"), IE("ie"){public String toString() {return "Internet Browser";}}, NETSCAPE("netscape"); Browser(String name){} public static void main(String args[]) { for (Browser browser:Browser.values()) System.out.println(browser); } }
a FIREFOX// www .ja v a 2 s .co m Internet Browser NETSCAPE b FIREFOX INTERNET BROWSER NETSCAPE c FIREFOX IE NETSCAPE d firefox ie netscape
a
An enum extends class java.lang.Enum, which extends class java.lang.Object.
Each enum constant inherits method toString()
defined in class java.lang.Enum.
Class java.lang.Enum overrides method toString()
to return the enum constant's name.
An enum constant can override any of the methods that are inherited by it.
The enum Browser defines a constructor that accepts a String method parameter, but it doesn't use it.
All enum constants, except enum constant IE, print the name of the constant itself.