my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K&B SCJP 5: topic page 62 second example 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 "K&B SCJP 5: topic page 62 second example" Watch "K&B SCJP 5: topic page 62 second example" New topic
Author

K&B SCJP 5: topic page 62 second example

MatthewTheNth Smith
Greenhorn

Joined: Apr 03, 2007
Posts: 2
A member of our study group pointed out the following.

The second example of page 62, showing an enum as in inner class does not compile. The Coffee object (defined on page 61) cannot see the enum, because it is an inner class:



To get it to compile, you can change Coffee to reference the enum in CoffeeeTest1? like



or, move Coffee into the CoffeeTest1 as a static inner class. It must be static.


[ April 03, 2007: Message edited by: MatthewTheNth Smith ]
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Hi Smith,

Yeah, if enum is public, it must be placed in an independent file, while enum definition can come under a class too.

This is the rule that in a file there can be at most one public class. So therefore if enum is public and not inside the class definition it must be kept in an independent file. Inside the class definition it can be private or protected or public. But independently only public can be used, no modifier default access as usually.

Thanks and Regards,
cmbhatt


cmbhatt
MatthewTheNth Smith
Greenhorn

Joined: Apr 03, 2007
Posts: 2
Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: K&B SCJP 5: topic page 62 second example
 
Similar Threads
Enums
Doubt regarding enum
enums
Regarding accessing of enum declared inside and outside a class