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?
final
static
private
protected
volatile
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.

Khaled said:   1 decade ago
I think its not a valid question either. In inner class private method is accessible from other method too.

Schad said:   1 decade ago
Inner classes can be protected and private.

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?

Bfhj said:   1 decade ago
But we can access the private members in the class which they are defined.

ChronosHD said:   1 decade ago
Final, static and volatile are out of the question, protected doesnt change anything and private restricts the access.

Tino said:   1 decade ago
Classes cannot be define as protected. Then how it is possible?

Post your comments here:

Your comments will be displayed after verification.