Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enums

 
Akanksha Joy
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The code is taken from the K&B book page 62 chapter1 (latest edition). There are many ways to declare an enum. The above is one the way i.e inside a class. But its not working. There's error in compiling. I think the enclosing class name is required...it's as if a nested class.......
 
Madhu Desai
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure what is in line 12 (cause when i was doing the same chapter i too aways typed Cofee instead Coffee)
 
Akanksha Joy
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh that's the typing mistake. The error is still there. I think if enum is declared in some class then it has to be accessed with the class name.
 
Alfred Swensen
Greenhorn
Posts: 10
Netbeans IDE PHP VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cannot find this example in my K&B Java6 from 2008 although there are many similar examples around page 61-64.
Your example cannot work because if the Coffee class is outsite of CoffeeTest3, how can the compile know what CoffeeSize inside Coffee should be?
If Coffee is put inside CoffeeTest3 as the comment suggests, it works.

bye
 
Lukas Sieradzki
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Akanksha Joy wrote:
The code is taken from the K&B book page 62 chapter1 (latest edition). There are many ways to declare an enum. The above is one the way i.e inside a class. But its not working. There's error in compiling. I think the enclosing class name is required...it's as if a nested class.......


In class Coffee just type CoffeeTest2.CoffeSize instead of CoffeeSize and everything will be allright.
If you want to reach inner class from outer class you should use the full path. The same if you want to run a class within console and that class is inside a package: then you type -> java package.MyMagicClass

All the best!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic