This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
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

Win a copy of Elasticsearch in Action this week in the Big Data forum!
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
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
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