Java Programming - Declarations and Access Control - Discussion
Discussion Forum : Declarations and Access Control - General Questions (Q.No. 10)
10.
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?
Answer: Option
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.
Discussion:
3 comments Page 1 of 1.
Amaziane said:
1 decade ago
But the question concern classes to have access to members of another class in the same package.
Private authorize just members of class to access each other but not outside of this class, if you want, in the same package, to access from class A a class B you have to have at least class B with default member access?
Private authorize just members of class to access each other but not outside of this class, if you want, in the same package, to access from class A a class B you have to have at least class B with default member access?
Sujit said:
1 decade ago
When we are talking about same class, most restrictive access should be Private. Default is restrictive only for different package.
Am I right?
Am I right?
Girish said:
1 decade ago
well explained
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers