enum Enum1
{
BIG(8), HUGE(10)
{
public String getName()
{
return "Huge";
}
public String getContry()
{
return "India";
}//additional Method
},
OVERWHELMING(16)
{
public String getName()
{
return "OVERWHELMING";
}
};
private int ounces;
public int getOunes()
{
return ounces;
}
public String getName()
{
return "Ponds";
}
Enum1(int ounces1)
{
ounces = ounces1;
}
}
class EnumAsInnerClass
{
Enum1 enumInnerClass;
public static void main(String[] args)
{
EnumAsInnerClass big = new EnumAsInnerClass();
big.enumInnerClass = Enum1.BIG;
EnumAsInnerClass over = new EnumAsInnerClass();
over.enumInnerClass = Enum1.OVERWHELMING;
EnumAsInnerClass huge = new EnumAsInnerClass();
huge.enumInnerClass = Enum1.HUGE;
System.out.println(big.enumInnerClass.getName());//Ponds
System.out.println(over.enumInnerClass.getName());//OVERWHELMING
System.out.println(huge.enumInnerClass.getName());//Huge
}
}
考虑上面的例子.如何调用方法getCountry for HUGE?
如果无法调用此方法,为什么Java将其视为合法?