Java Programming - Declarations and Access Control - Discussion
Discussion Forum : Declarations and Access Control - General Questions (Q.No. 17)
17.
Given a method in a protected class, what access modifier do you use to restrict access to that method to only the other members of the same class?
Answer: Option
Explanation:
The private access modifier limits access to members of the same class.
Option A, B, D, and E are wrong because protected are the wrong access modifiers, and final, static, and volatile are modifiers but not access modifiers.
Discussion:
6 comments Page 1 of 1.
Chad said:
1 decade ago
Same comment as @Tino, how is this a valid question? Are we supposed to assume we're talking about a nested class here?
ChronosHD said:
1 decade ago
Final, static and volatile are out of the question, protected doesnt change anything and private restricts the access.
Khaled said:
1 decade ago
I think its not a valid question either. In inner class private method is accessible from other method too.
Bfhj said:
1 decade ago
But we can access the private members in the class which they are defined.
Tino said:
1 decade ago
Classes cannot be define as protected. Then how it is possible?
Schad said:
1 decade ago
Inner classes can be protected and private.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers