You can see what this means with a small example.
Here we have a class with some package-private
visibility variables, the visibility applied when not using a visibility keyword.
package insider;
public class PrivateClass {
static int var1 = 10;
static String var2 = "Secret";
}
Here I have a class in another package. This will throw none visibility errors for the variables.
package outsider;
import insider.PrivateClass;
public class OutsiderClass {
public static void outsider() {
System.out.println(PrivateClass.var2 + " " + PrivateClass.var1);
}
}
Here I have a class in the same package as our package-private
variables class. This one does not throw an error when accessing the variables.
package insider;
public class InfiltratorClass {
public static void infiltrator() {
System.out.println(PrivateClass.var2 + " " + PrivateClass.var1);
}
}
File Structure Overview:
insider
PrivateClass
InfiltratorClass
outsider
OutsiderClass