From JavaProgramming. Visibility of class members is almost the same as in C++, with a couple of important exceptions: ''Default (no visibility specified)'' * Not visible outside the class, '''except for classes in the same package''' * Not visible from subclasses ''Private'' * Not visible outside the class * Not visible from subclasses ''Protected'' * Not visible outside the class, '''except for classes in the same package''' * Visible from subclasses ''Public'' * Visible outside the class * Visible from subclasses Here is a test program to demonstrate visibility: /* T''''''estVisibility.java */ class Classname { int defaultVar; public int publicVar; protected int protectedVar; private int privateVar; } public class T''''''estVisibility { public static void main(String[] args) { Classname foo = new Classname(); foo.defaultVar++; // Visible within the package foo.publicVar++; // Evidently public visibility foo.protectedVar++; // Visible within the package!!! foo.privateVar++; // Compiler error: privateVar has private access } }