For example I have a file name call “A.java”. Here its structure:
public class A{
}
private class B{
// no error
}
public class C{
//error : must declare at different file
}
I think this is Java rules. But, I really want to know: WHY java need to do that.
Thanks 🙂
This shouldn’t even work (see Java Language Specification):
Are you sure you haven’t declared class
Bas an inner class?It doesn’t make sens to declare a top-level class as
private, since private restricts the visibility of members to the enclosing top-level class/interface. If your class is a top-level class (whether or not in its own file), you’d at least want package-level visibility (no modifier at all).