my dog learned polymorphism
The moose likes Mock Exam Errata and the fly likes Rules Roundup Q309 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Rules Roundup Q309" Watch "Rules Roundup Q309" New topic

Rules Roundup Q309

Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
The answer to this question is incorrect.
Q: TRUE or FALSE: methods which are marked protected can be accessed only by classes within the same package
A: Answer: FALSE Protected means "any subclass, regardless of package, can inherit these members -- methods or data".
The question is not about inheritance. As it stands the answer is ambiguous, there is something to say for both TRUE and FALSE:
The methods can only be accessed by methods in the same class, which makes it a subset of the package.

Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Jeroen,
Let's see what the JLS says about protected methods.

Protected methods are visible (accessible) to the package and all subclasses.

Now let's look at the question.

Methods which are marked protected can be acessed only by classes within the same package.

Comparing these two sentences do we see any differences between them. In case you missed it, the word ONLY jumps right out!
It is only in the second quote which would make the first quote incorrect. But JLS is the rule! Therefore, we must humbly bow our heads and mumble under our breath:
FALSE ....
I agree. Here's the link:
subject: Rules Roundup Q309
It's not a secret anymore!