Search code examples
javainterfaceprivateprotected

Access Specifier for Interface Declaration


Why protected/private access specifier cannot be used Interfaces declaration ?


Solution

  • You can declare a protected class or indeed a private one - but only within another one. At that point it's either visible to classes derived from the outer one (in the case of protected) or not (in the case of private):

    public class Outer
    {
        private static class NotVisibleToSubclassesOfOuter {}
    
        protected static class VisibleToSubclassesOfOuter {}
    }