Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. public class SomeClass {
  2. static {
  3. System.out.println("Static initialize... OK");
  4. // Block executes first.
  5. // This block executes even if no instances instantiated.
  6. }
  7.  
  8. {
  9. System.out.println("Instance initialize... OK");
  10. // Block executes second.
  11. // This block executes when instance is instantiated BEFORE the constructor.
  12. }
  13.  
  14. public SomeClass() {
  15. System.out.println("Constructor initialize... OK");
  16. // Constructor executes third.
  17. }
  18.  
  19. public static void main(String[] args) {
  20. new SomeClass();
  21. // Result:
  22. // Static initialize... OK
  23. // Instance initialize... OK
  24. // Constructor initialize... OK
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement