Which access modifier allows members to be accessed only by classes in the same package?
Default access is package-private.
Why this answer
In Java, the default (package-private) access modifier, which is applied when no explicit modifier is used, restricts member access to only classes within the same package. This is the only access level that provides package-level visibility without inheritance or subclass access.
Exam trap
Oracle often tests the misconception that 'default' is a keyword or that package-private access is explicitly declared with a modifier, when in fact it is the absence of any modifier, and candidates may confuse it with 'protected' which also allows package access but adds inheritance access.
How to eliminate wrong answers
Option A is wrong because 'protected' allows access to subclasses (even in different packages) and all classes in the same package, which is broader than package-only access. Option C is wrong because 'private' restricts access to only the declaring class itself, not to other classes in the same package. Option D is wrong because 'public' allows access from any class in any package, which is the most permissive modifier.