Advertisement
cd62131

static initialization block

May 24th, 2018
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.42 KB | None | 0 0
  1. public class C {
  2.   public static C[] x;
  3.  
  4.   static {
  5.     x = new C[10];
  6.     for (int i = 0; i < x.length; ++i) {
  7.       x[i] = new C("name" + i);
  8.     }
  9.   }
  10.  
  11.   public static void main(String[] args) {
  12.     for (final C e: C.x) {
  13.       System.out.println(e.getName());
  14.     }
  15.   }
  16.  
  17.   private final String name;
  18.  
  19.   public C(String name) {
  20.     this.name = name;
  21.   }
  22.  
  23.   public String getName() {
  24.     return name;
  25.   }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement