You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Main.java 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package protectedAccess;
  2. import org.aspectj.testing.Tester;
  3. import protectedAccess.p1.C1;
  4. public class Main {
  5. public static void main(String[] args) {
  6. SubC1 subc1 = new SubC1();
  7. subc1.m(subc1, subc1);
  8. }
  9. }
  10. class SubC1 extends C1 {
  11. public void m(SubC1 subc1, C1 c1) {
  12. Tester.checkEqual(this.s, "protected");
  13. Tester.checkEqual(this.m(), "protected");
  14. Tester.checkEqual(s, "protected");
  15. Tester.checkEqual(m(), "protected");
  16. Tester.checkEqual(subc1.s, "protected");
  17. Tester.checkEqual(subc1.m(), "protected");
  18. C1 c1a = new C1() { };
  19. C1 c1b = new C1(); //ERROR: illegal protected access
  20. Tester.checkEqual(c1.s, "protected"); //ERROR: illegal protected access
  21. Tester.checkEqual(c1.m(), "protected"); //ERROR: illegal protected access
  22. Tester.checkEqual(c1.m(), "protected"); //ERROR: illegal protected access
  23. }
  24. class SubI1 extends I1 {
  25. public void m(SubC1 subc1, C1 c1, I1 i1) {
  26. Tester.checkEqual(s, "protected");
  27. Tester.checkEqual(m(), "protected"); //ERROR: method not found
  28. Tester.checkEqual(SubC1.this.s, "protected");
  29. Tester.checkEqual(SubC1.this.m(), "protected");
  30. Tester.checkEqual(subc1.s, "protected");
  31. Tester.checkEqual(subc1.m(), "protected");
  32. Tester.checkEqual(c1.s, "protected"); //ERROR: illegal protected access
  33. Tester.checkEqual(c1.m(), "protected"); //ERROR: illegal protected access
  34. Tester.checkEqual(si, "ip");
  35. Tester.checkEqual(mi(), "ip");
  36. Tester.checkEqual(this.si, "ip");
  37. Tester.checkEqual(this.mi(), "ip");
  38. Tester.checkEqual(i1.si, "ip"); //ERROR: illegal protected access
  39. Tester.checkEqual(i1.mi(), "ip"); //ERROR: illegal protected access
  40. }
  41. }
  42. protected String mString(Object o) {
  43. return o.toString();
  44. }
  45. }