0

I had to shorten the title a bit. Here's the full question:

In Java which access modifier allows a member to be accessed only by the subclasses in other package or any class within the package of that member's class?

I am thinking protected but my office mate says the answer is private.

2rs2ts
  • 10,662
  • 10
  • 51
  • 95

4 Answers4

1

In Java which access modifier allows a member to be accessed only by the subclasses in other package or any class within the package of that member's class?

enter image description here

Maxim Shoustin
  • 77,483
  • 27
  • 203
  • 225
1

see this might help..you ! this is the scope of all access modifiers in java.

enter image description here

Saurabh Sharma
  • 489
  • 5
  • 20
0

Visibility of the properties of class for different access modifiers

——————————————————————————————————————

1) From the same class

      Public , Protected, Private and Default

2) From any class in same package

      Public, Protected and Default

3) From a subclass in same package

      Public, Protected and Default

4) From subclass outside the same package

      Public and Protected (by inheritance)

5) From any non-subclass or class outside the package

      Public only
Not a bug
  • 4,286
  • 2
  • 40
  • 80
-1

It can't be private because private member methods are accessible only within the same class.

protected does not mean that a member will be accessed only by a subclass it specifically means that the classes are accessible within a package.

Your question is either wrong or you missed something on the way of asking your doubt.

Please have a look at the following :

http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html

Ritz
  • 180
  • 1
  • 12
  • Ritz - thanks. I will go back and look at the details. The question was translated from Japanese so I think something was lost in translation :-( –  Jan 15 '14 at 09:20