Default accessor occurs when public, protected, or private are not specified.
Default accessor applies to classes, interfaces, variables, methods, and constructors.
Default accessor allows the declared item to be accessed by any class or interface of the same package.
Default and protected members differ only when subclasses are involved
Default members can be accessed only by classes in the same package.
protected members can be accessed by other classes in the same package, plus subclasses regardless of package.
protected = package + subclass kids.
package certification;
public class OtherClass {
void testIt() { // No modifier means method has default access
System.out.println("OtherClass");
}
}
In another source code file you have the following:
package somethingElse;
import certification.OtherClass;
class AccessClass {
static public void main(String[] args) {
OtherClass o = new OtherClass();
o.testIt();
}
}
|