If an outer class can’t have “protected” modifier in Java because the sub-classes of it will only be able to use it, why Java allows a modifier for classes in a source file(other than public), even though its scope of accessibility is even lower?
class A{
private class B{}
protected class C{}
public class D{}
class E{}
}
public class Test{
public static void main(String[] args){
System.out.println("Test class");
}
}
Here the outer class A of the single source file has default access modifier. Now, bottom is a "A" class in the source file that's not allowed in Java is:
protected class A{
private class B{}
protected class C{}
public class D{}
class E{}
}
public class Test{
public static void main(String[] args){
System.out.println("Test class");
}
}
My question is if a default modifier is allowed for an outer class, why a protected modifier isn't allowed even though default modifier has a lesser scope than . Protected can be accessed through Same class, Same package and Sub-class. Default can be accessed through only Same class and Same package. Why is the second process invalid even though the first one is valid. My question is if protected doesn't make sense how can default make sense?