1). How does this resolve, Please have a look at case statement number one?
public class Enum {
/**
* @param args
*/
public static void main(
String[] args) {
CS.CoffeeSizes cs = CS.CoffeeSizes.BIG;
System.out.println(cs);
System.out.println(CoffeeSize.BIG);
makeSelection(cs);
}
static void makeSelection(CS.CoffeeSizes cs) {
switch(cs) {
case BIG: // HERE HOW DOES COMPILER KNOW THAT WE ARE
//REFFEREING TO CS.CoffeeSizes.BIG and not CS1.CoffeeSizes.BIG
System.out.println("do "+cs);
break;
case LARGE:
System.out.println("do "+cs);
break;
default:
System.out.println("default");
}
}
}
class CS {
enum CoffeeSizes {BIG, LARGE, EXTRA_LARGE}
}
class CS1 {
enum CoffeeSizes {BIG, LARGE, EXTRA_LARGE}
}
2)In above code if i replace BIG with CS.CoffeeSizes.BIG , I get a compiler error
"The enum constant CS.CoffeeSizes.LARGE reference cannot be qualified in a case label"
Why do i get this error? SHouldnt this be the correct way of reffering BIG and not just typing BIG without telling the compiler to which enumeration does this "BIG: belong?