Advertisement
Guest User

static block initialization

a guest
May 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.49 KB | None | 0 0
  1. public class Klazz2 {
  2.     private static String name = null;
  3.  
  4.     static {
  5.         name = "dupa";
  6.     }
  7.  
  8.     public static String getName() {
  9.         return name;
  10.     }
  11. }
  12.  
  13. public class Klazz1 {
  14.     static {
  15.         initialize();
  16.     }
  17.  
  18.     public static void initialize(){
  19.         System.out.println(Klazz2.getName());
  20.     }
  21.  
  22.     public static void doNothing(){}
  23. }
  24.  
  25. public class App {
  26.     public static void main(String[] args) {
  27.         Klazz1.doNothing();
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement