Java protected modifier accessible in another package having the same package name <p>I have programmed in Java for some time and I just realized that the <code>protected</code> access modifier allows members to be accessed also in the <em>same package</em>. So here is the situation and the question:</p> <p>I have a class having a <code>protected</code> method, and a test class using Mockito to stub that method. The two classes are located in different folders (a <em>src</em> and a <em>test</em>), but their package names are the same! The funny thing is, I can call the protected method in the test class! I would like to know how it is possible? Because their package names are the same? In this case the <code>protected</code> modifier does allow a very wide access!</p>