Advertisement
Guest User

Untitled

a guest
Jan 20th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1.     class FooTest {
  2.  
  3.         public static String stuff = "";
  4.  
  5.  
  6.  
  7.         public static void main (String[] args) {
  8.             FooTest t = new FooTest();
  9.             t.go();
  10.         }
  11.  
  12.         public void go() {
  13.  
  14.             Foo f1 = new Foo();
  15.  
  16.             // instance of anon subclass
  17.             Foo f2 = new Foo(){
  18.                 public void say () {
  19.                     System.out.println("Modded Foo says: " + stuff);
  20.                 }
  21.             };
  22.            
  23.             f1.whichClassAmI();
  24.             f2.whichClassAmI();
  25.  
  26.             stuff = "stuff";
  27.             f1.say();
  28.             f2.say();
  29.            
  30.             Foo f3 = f1.getAnotherFoo(); // <-- enclosing class is null
  31.             f3.say();
  32.            
  33.             Foo f4 = f2.getAnotherFoo(); // <-- works now
  34.             stuff = "cloned stuff";
  35.             f4.say();
  36.         }
  37.  
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement