package com.xiaoshan.accessmodifier.onepack;
import com.xiaoshan.accessmodifier.anotherpack.AnotherPackClass;
import com.xiaoshan.accessmodifier.anotherpack.AnotherPackSonClass;
public class OneClass {
public String publicVariable = "Public Variable";
protected String protectedVariable = "Protected Variable";
String defaultVariable = "Default Variable";
private String privateVariable = "Private Variable";
public void method(){
String variable = this.publicVariable;
System.out.println("本类可以访问到:" + variable);
variable = this.protectedVariable;
System.out.println(variable);
variable = this.defaultVariable;
System.out.println(variable);
variable = this.privateVariable;
System.out.println(variable);
}
public static void main(String[] args) {
OneClass clazz = new OneClass();
clazz.method();
SamePackClass samePackClass = new SamePackClass();
samePackClass.method();
AnotherPackSonClass anotherPackSonClass = new AnotherPackSonClass();
anotherPackSonClass.method();
AnotherPackClass anotherPackClass = new AnotherPackClass();
anotherPackClass.method();
}
}