• Post Reply Bookmark Topic Watch Topic
  • New Topic

question on enums  RSS feed

Jens Mayer
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm studying for my SCJP Exam an i have a question concerning enums and static fields:

I tried to increment a static variable from an enum-constructor. It doesn't compile. Look at the code:

enum BeerSize {

SMALL(300), MEDIUM(500), BIG(1000);

private int volume;
private static int sizeCount=0;

BeerSize(int vol) {
sizeCount++; // this doesn't compile
this.volume = vol;

public void setSize(int vol) {
this.volume = vol;

public int getSize() {
return this.volume;

public void printSize() {
System.out.println("This means "+this.volume+" ml of beer");

the compiler won't let me access the static variable "sizeCount" from within the constructor.
Can anybody tell me why ? In a "normal" class it works fine...

greetz from hamburg, germany

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!