Hey guys,
I was wondering about the use of private constructor inside an enum which is outside the class........I am still able to initialize the object from another class, rite??
And why is public not allowed there???
package javaapplication3;
enum coffeeSize { Big(1), Small(4), Verysmall(5);
public int points;
private coffeeSize(int points)
{
System.out.println("hello");
this.points = points;
}
int getval()
{
return points;
}
}
public class Main
{
public static void main(String [] args)
{
coffeeSize size = coffeeSize.Small;
// coffeeSize cs [] = size.values();
// for(coffeeSize cl : cs)
System.out.println(size);
}
}
Output:
run:
hello
hello
hello
Small
BUILD SUCCESSFUL (total time: 0 seconds)
Thanks .