Java MCQ: Which access modifier is used to allow access to members of a class within the same package but not from outside?
Answer:
Explanation:
In Java, when no access modifier is specified for a class member, the default access level is package-private, also known simply as “default.” This means the member is accessible only within the same package but not from outside the package.
This access level is useful when you want to restrict access to certain class members, allowing only classes within the same package to access them. This promotes encapsulation within a package and helps to organize code into logical groupings.
Understanding access modifiers is crucial for controlling visibility and access to class members, thereby protecting the integrity of your code.
Reference links:
https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html