Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Enums Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Enums" Watch "Enums" New topic
Author

Enums

Akanksha Joy
Greenhorn

Joined: Jun 05, 2009
Posts: 17

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

Joined: Jun 14, 2009
Posts: 42
Are you sure what is in line 12 (cause when i was doing the same chapter i too aways typed Cofee instead Coffee)


Thanks
Preparing for SCJP 6
Akanksha Joy
Greenhorn

Joined: Jun 05, 2009
Posts: 17
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

Joined: May 25, 2009
Posts: 10

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

Joined: Jun 09, 2009
Posts: 32
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!
 
Don't get me started about those stupid light bulbs.
 
subject: Enums
 
Similar Threads
K&B SCJP 5: topic page 62 second example
Enum
Doubt regarding enum
simple enum doubt?
enums