File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Public Member Access Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Public Member Access" Watch "Public Member Access" New topic

Public Member Access

leo donahue
Ranch Hand

Joined: Apr 17, 2003
Posts: 327
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 ]

Thanks, leo
Kathy Sierra
Cowgirl and Author

Joined: Oct 10, 2002
Posts: 1589
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
leo donahue
Ranch Hand

Joined: Apr 17, 2003
Posts: 327
Thanks for your response. Nothing to be sorry about. I just wanted to be sure I was following your example correctly.
I agree. Here's the link:
subject: Public Member Access
It's not a secret anymore!