Can a top-level class be marked as private? The provided answer is "no". A static inner class is considered to be a top level class and it can be marked private. Therefore, this answer is wrong. Somebody should notify management!
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18652
posted
0
Rather than changing the answer though, I'd rephrase the question slightly. Replace "top-level class" with "regular top-level class", "top-level (non-nested) class", or something like that. Annoyingly, Sun's terminology has left us without a concise unambiguous term for good old-fashioned top-level classes.
I've heard "package level" applied to the classes whose fully qualified names consist of only the package name and ONE class name...
Tony Alicea Senior Java Web Application Developer, SCPJ2, SCWCD
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18652
posted
0
Yeah, I forgot that one. I don't think Sun officially defined it though, so it's not as well-known as I'd like. As for whether to re-write the question or the answer, I suppose either one works, depending on what you want to test people on. I think people should know that (a) package-level classes cannot be private, and (b) nested top-level classes can be private. Test on whichever fact you want, or both. Curiously, package-level classes can be public or default (package) access, but not protected. This seems strange to me since protected is in between the other two in terms of permissiveness. Probably not a good test question though...
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18652
posted
0
Hmmm... the just-released draft of the JLS 2nd edition now seems to define top-level classes to exclude static nested classes (which will now also be known as static member classes, but not static inner classes). I think that's a good move to clear up some of the muddy usage that we've seen in the past - we'll see though if it stays that way in the final version. Of course this has no effect yet on the actual exam, which apparently does use the term "static inner class" even though the existing specs say that a static nested class is not an inner class. Sigh. So there will still be confusion on this issue for some time. So, back to the issue at hand: Q: Can a top-level class be marked as private? A: The correct answer is yes right now, but it could well be no in the future. Q: Can a top-level (regular or package-level) class be marked as private? A: No.
Rich Wardwell
Ranch Hand
Joined: Jan 20, 2000
Posts: 33
posted
0
To be honest, one of the reasons I've always enjoyed the rules roundup was because it was fairly clear and unambiguous - trick questions were cunning but fair. A challenging question is certainly acceptable, but changing the answer on this one without clarifying the question all considering would be evil! My suggestion is to modify the question to make it more clear or remove the question altogether.
<B>Rich Wardwell</B><BR> <A HREF="mailto:rcw3@levelpath.com" rel="nofollow">rcw3@levelpath.com</A> <BR>Sun Certified Programmer for the Java 2 Platform