1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- package protectedAccess;
-
- import org.aspectj.testing.Tester;
- import protectedAccess.p1.C1;
-
- public class Main {
- public static void main(String[] args) {
- SubC1 subc1 = new SubC1();
- subc1.m(subc1, subc1);
- }
- }
-
- class SubC1 extends C1 {
- public void m(SubC1 subc1, C1 c1) {
- Tester.checkEqual(this.s, "protected");
- Tester.checkEqual(this.m(), "protected");
-
- Tester.checkEqual(s, "protected");
- Tester.checkEqual(m(), "protected");
-
- Tester.checkEqual(subc1.s, "protected");
- Tester.checkEqual(subc1.m(), "protected");
-
- C1 c1a = new C1() { };
-
- C1 c1b = new C1(); //ERROR: illegal protected access
-
- Tester.checkEqual(c1.s, "protected"); //ERROR: illegal protected access
- Tester.checkEqual(c1.m(), "protected"); //ERROR: illegal protected access
-
- Tester.checkEqual(c1.m(), "protected"); //ERROR: illegal protected access
- }
-
- class SubI1 extends I1 {
- public void m(SubC1 subc1, C1 c1, I1 i1) {
- Tester.checkEqual(s, "protected");
- Tester.checkEqual(m(), "protected"); //ERROR: method not found
-
- Tester.checkEqual(SubC1.this.s, "protected");
- Tester.checkEqual(SubC1.this.m(), "protected");
-
- Tester.checkEqual(subc1.s, "protected");
- Tester.checkEqual(subc1.m(), "protected");
-
- Tester.checkEqual(c1.s, "protected"); //ERROR: illegal protected access
- Tester.checkEqual(c1.m(), "protected"); //ERROR: illegal protected access
-
- Tester.checkEqual(si, "ip");
- Tester.checkEqual(mi(), "ip");
-
- Tester.checkEqual(this.si, "ip");
- Tester.checkEqual(this.mi(), "ip");
-
- Tester.checkEqual(i1.si, "ip"); //ERROR: illegal protected access
- Tester.checkEqual(i1.mi(), "ip"); //ERROR: illegal protected access
- }
- }
-
- protected String mString(Object o) {
- return o.toString();
- }
- }
|