Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

K&B SCJP 5: topic page 62 second example

 
MatthewTheNth Smith
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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 ]
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic