public class ProtectedClass {
private String name;
public static void changeName(ProtectedClass pc, String newName) {
pc.name = newName;
}
public ProtectedClass(String s) { name = s; }
public String toString() { return name; }
public static void main(String[] args) {
ProtectedClass
pc1 = new ProtectedClass("object1"),
pc2 = new ProtectedClass("object2");
pc2.changeName(pc1, "new string"); // expect ERROR/EXCEPTION
System.out.println(pc1);
}
} ///:~
Considering above Java source code,it could easily concluded that the Java programming language could only provide class-level access control/protect.Are there any programming languages providing object-level access control/protect?
thanks.
P.S:This problem is derived from this question Java: Why could base class method call a non-exist method?I want to give my appreciation to TofuBeer.