Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by whitelisting our website.

You want a class to have access to members of another class in the same package. Which is the most restrictive access that accomplishes this objective?

Question: You want a class to have access to members of another class in the same package. Which is the most restrictive access that accomplishes this objective?
[A].

public

[B].

private

[C].

protected

[D].

default access

Answer: Option D

Explanation:

The only two real contenders are C and D. Protected access Option C makes a member accessible only to classes in the same package or subclass of the class. While default access Option D makes a member accessible only to classes in the same package.