• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

K&B SCJP 5: topic page 62 second example

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
MatthewTheNth Smith
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic