A
private
class member or constructor is accessible only within the class body in
which the member is declared and is not inherited by subclasses. In the example:
class Point {
Point() { setMasterID(); }
int x, y; private int ID; private static int masterID = 0;
private void setMasterID() { ID = masterID++; }
}
the private
members ID,
masterID
, and setMasterID
may be used only
within the body of class Point
. They may not be accessed by qualified names,
field access expressions, or method invocation expressions outside the body of the
declaration of Point
.
See §8.6.8 for an example that uses a private
constructor.