Java Programming - Declarations and Access Control - Discussion

6. 

What is the most restrictive access modifier that will allow members of one class to have access to members of another class in the same package?

[A]. public
[B]. abstract
[C]. protected
[D]. synchronized
[E]. default access

Answer: Option E

Explanation:

default access is the "package oriented" access modifier.

Option A and C are wrong because public and protected are less restrictive. Option B and D are wrong because abstract and synchronized are not access modifiers.


Jaz said: (Sep 1, 2011)  
Why? anyone can explain.

Ram said: (Nov 16, 2013)  
But default access id public only.

Pinkesh Baghel said: (Mar 30, 2014)  
Public - we can access anywhere.
Protected - we can access out of package.
Default - we can access in same package anywhere.

Due to this default is correct.

Shubham said: (Aug 24, 2019)  
Default access specifier is more restrictive and have access in same.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.