Package private is the default access-control modifier in Java. If a member of a class is not annotated with `private`, `protected`, or `public`, then the member is `package private` by default. When a member is `package-private`, it can only be accessed by the parent class, and other classes in the same package.
Consider the following classes:
package my.stuff;
class Foo {
private int a;
int b;
}
package my.stuff;
public class Bar {
private int c;
private int d;
}
package my.otherstuff;
public class Baz {
private int c;
private int d;
}
Class Foo
is accessible from class Bar
, but not from class Baz
. This is because both Foo
and Bar
are in the same package (my.stuff
). Also, the field Foo.b
is accessible from Bar
, but not from Baz
for the same reasons.