Advertisement
jaVer404

level15.lesson12.home06

Jul 18th, 2015
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. package com.javarush.test.level15.lesson12.home06;
  2.  
  3. /* Порядок загрузки переменных
  4. Разобраться, что в какой последовательности инициализируется.
  5. Исправить порядок инициализации данных так, чтобы результат был следующим:
  6. static void init()
  7. Static block
  8. public static void main
  9. non-static block
  10. static void printAllFields
  11. 0
  12. null
  13. Solution constructor
  14. static void printAllFields
  15. 6
  16. First name
  17. */
  18.  
  19. public class Solution {
  20.     static {
  21.         init();
  22.     }
  23.     static {
  24.         System.out.println("Static block");
  25.     }
  26.  
  27.     {
  28.         System.out.println("non-static block");
  29.         printAllFields(this);
  30.     }
  31.  
  32.     public int i = 6;
  33.  
  34.     public String name = "First name";
  35.  
  36.  
  37.     public Solution() {
  38.         System.out.println("Solution constructor");
  39.         printAllFields(this);
  40.     }
  41.  
  42.     public static void init() {
  43.         System.out.println("static void init()");
  44.     }
  45.  
  46.     public static void main(String[] args) {
  47.         System.out.println("public static void main");
  48.         Solution s = new Solution();
  49.     }
  50.  
  51.     public static void printAllFields(Solution obj) {
  52.         System.out.println("static void printAllFields");
  53.         System.out.println(obj.i);
  54.         System.out.println(obj.name);
  55.  
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement