Guest User

Java private method

a guest
Jan 5th, 2016
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.49 KB | None | 0 0
  1.     @Test
  2.     @Ignore
  3.     public void privateMethod() {
  4.         C c1 = new C(1);
  5.         C c2 = new C(2);
  6.  
  7.         System.out.println(c2.test(c1));
  8.         System.out.println(c1.test(c2));
  9.     }
  10.  
  11.     private class C {
  12.         private int x = 1;
  13.  
  14.         public C(int x) {
  15.             this.x = x;
  16.         }
  17.  
  18.         private int m() {
  19.             return x;
  20.         }
  21.  
  22.         public int test(C other) {
  23.             return other.m();
  24.         }
  25.     }
  26.  
  27. // Prints out:
  28. // 1
  29. // 2
Advertisement
Add Comment
Please, Sign In to add comment