Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SomeClass {
- static {
- System.out.println("Static initialize... OK");
- // Block executes first.
- // This block executes even if no instances instantiated.
- }
- {
- System.out.println("Instance initialize... OK");
- // Block executes second.
- // This block executes when instance is instantiated BEFORE the constructor.
- }
- public SomeClass() {
- System.out.println("Constructor initialize... OK");
- // Constructor executes third.
- }
- public static void main(String[] args) {
- new SomeClass();
- // Result:
- // Static initialize... OK
- // Instance initialize... OK
- // Constructor initialize... OK
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement