File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing enums

 
midhuna peru
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys! I was trying out enums. The following code works fine.

Output is


Now next i was trying to use enum CoffeeSize directly. Here is the code

It shows me the following error.


What does it mean? I din't understand why CoffeeSize is not initialized here and what is happening in previous code regarding this.
 
Stephan van Hulst
Bartender
Pie
Posts: 4826
34
Chrome Netbeans IDE Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This has nothing to do with enums.

You may not access a variable before it's initialized. Member variables get initialized to a default value automatically, if you don't assign a value to them. Local variables do not, you always have to assign a value to them explicitly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic