0

I think I spotted a contradiction in the java official documentation here: http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html

On one hand, it says:

" If the subclass is in the same package as its parent, it also inherits the package-private members of the parent."

after which, it says:

A subclass does not inherit the private members of its parent class.

Aren't they contradictory statements? I would think the second statement is correct. Private fields can be accessed only within the class that it defines them (unless we have defined private or protected get accessors in that class). Thank you.

Samy
  • 465
  • 1
  • 10
  • 25

1 Answers1

1

package-private is different than private even though the name "private" is in both.

package-private is when you don't have any qualifier on the member

public class Bar{
    public int foo; // public
    int foo1; // package private
    private int foo2; //private
}
dkatzel
  • 31,188
  • 3
  • 63
  • 67
  • I understand now. I hadn't heard the term "package private" before. I was accustomed to the "default" term (no access qualifier). Now it makes sense. Come to think of it, the name is spot-on: the default modifier allows the field declared as such to be visible only within the same package. Thank you! – Samy Mar 20 '15 at 15:31