I created a public and private class in the same java file. It is not getting compiled.
However, if I keep a public class and a class without any access modifier, it is gets compiled.
What is the reason for this ?
Toplevel private class is nonsense, because no other class can access this class. That is why you get compilation error..
JLS states that ;
The access modifiers protected and private pertain only to member classes within a directly enclosing class declaration (§8.5) and are discussed in §8.5.1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With