Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 20th, 2012  |  syntax: Java  |  size: 0.88 KB  |  views: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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.     }