This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
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

Public Member Access

 
leo donahue
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
I'm having trouble understanding something, and I think an assumption is being made that I'm not aware of.
In Kathy and Bert's SCJP2 cert book on page 73 there is a class called Toon which invokes the doRooThings method on a Cloo instance.
However, should i assume that the Toon class is in the same package as Cloo? The text doesn't specify a package name for the Toon class. Here is the code:

I thought that since the Roo class is not marked public that only classes in the same package can access members of this class.
There isn't a package declaration for class Toon. Is it in the same package as Cloo? I know it looks like it is here in this example, but the book is unclear whether it is or isn't.
Also, since class Toon doesn't extend Cloo, then I'm invoking the method doRooThings in class Toon from the Cloo class, right?
[ May 21, 2003: Message edited by: leo donahue ]
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy -- you are absolutely right -- in order for this code to work, class Toon must have been declared in the same package as Cloo, since Cloo is not public.
We didn't specify it either way because, well, because I have no idea why. We should have made it explicit! But you figured out what must be true in order for that to work. We were concentrating on the actual doRooThings() method rather than the class itself.
Sorry, and thanks for the catch
cheers,
Kathy
 
leo donahue
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kathy,
Thanks for your response. Nothing to be sorry about. I just wanted to be sure I was following your example correctly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic