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.
posted 14 years ago
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 .... Regards, Manfred.