Originally posted by Uday Kumar:
"In a file, there may be more than 1 top-level class,isn't it?
and cann't be private or protected?"
What could be the reason for a top-level class cannot be protected?
[ January 31, 2002: Message edited by: Uday Kumar ]
Well, think about it logically.
If you have a top level class marked private, who can use it?
private class foo()
{
int anInt = 12;
}
Private means that only the class can access it. That means that only foo can access itslef. No other class could ever do anything with foo. That doesn't seem very useful does it?
Similarly, with protected, you're saying that classes within the same package can access it. But the default access already covers package access, so in this case supporting protected would be redundant. More serious however, is that if you allowed protected top-level classes, you would have a situation where outside the package, only subclasses of the class could instantiate the class; this would include constructors, so that would effectively prohibit you from instantiating a subclass that was not in the same package. Again, this is redundant behaviour, as the default access already provides for this functionality.
Rob