We all know that unless we specifically define a constructor, the compiler inserts an invisible constructor of the null parameter. I thought its access modifier was public, but when I ran into an inner class problem, I found that I was wrong. Here is my code:
public class Outer { protected class ProtectedInner {
And in another package there is a subclass of Outer :
public class SubOuterInAnotherPackage extends Outer { public static void main(String[] args) { SubOuterInAnotherPackage.ProtectedInner protectedInner = new SubOuterInAnotherPackage().new ProtectedInner();
You will get an error in the main() method, but if you add a public constructor to the ProtectedInner class, this error will be resolved. Therefore, I think that the default constructor modifier is not public! So can anyone tell me what the default constructor access modifier is?
java access-specifier
jason Feb 25 '14 at 7:14 2014-02-25 07:14
source share