Java protected modifier accessible in another package having the same package name

I have programmed in Java for some time and I just realized that the protected access modifier allows members to be accessed also in the same package. So here is the situation and the question:

I have a class having a protected method, and a test class using Mockito to stub that method. The two classes are located in different folders (a src and a test), 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 protected modifier does allow a very wide access!

Jon Skeet
people
quotationmark

If the package names are the same, the two classes are in the same package - it's as simple as that. The fact that they were built from different source directories is irrelevant - the only thing that identifies a package is its fully-qualified name.

people

See more on this question at Stackoverflow