Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 59 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. Anonymous Class in Java
  2. public static void main(String[] args) {
  3.  
  4.         AnonymousClass a = new AnonymousClass() {
  5.             int whatever = 1;
  6.         };
  7.  
  8.     System.out.println(a.whatever);
  9. }
  10.    
  11. public static void main(String[] args) {
  12.     System.out.println(new Object() {
  13.       int whatever = 1;
  14.     }.whatever);
  15. }
  16.    
  17. public static void main(String[] args) {
  18.     class Local {
  19.       int whatever = 1;
  20.     }
  21.     Local local = new Local();
  22.     System.out.println(local);
  23. }
  24.    
  25. public static void main(String[] args) {
  26.     class NotAnonymous {
  27.         public int whatever = 1;
  28.     }
  29.     NotAnonymous na = new NotAnonymous();
  30.     System.out.println(na.whatever);
  31. }
  32.    
  33. private interface AnonymousClass {
  34.  
  35. }
  36.  
  37. public static void main(String[] args) {
  38.  
  39.         AnonymousClass a = new AnonymousClass() {
  40.             int whatever = 1;
  41.         };
  42.  
  43.     System.out.println(a.whatever); // this won't work
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top