Slightly related to my other question: What is the difference between the following:
private class Joe
protected class Joe
public class Joe
class Joe
Once again, the difference between the last 2 is what I'm most interested in.
A public class is accessible to a class in any package.
A class with default access (class Joe) is only visible to other classes in the same package.
The private and protected modifiers can only be applied to inner classes.
A private class is only visible to its enclosing class, and other inner classes in the same enclosing class.
A protected class is visible to other classes in the same package, and to classes that extend the enclosing class.
See JLS for more info.
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