Last active
July 19, 2019 03:58
-
-
Save Harshal96/f040c27957d3c9313c58731f21432fe5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class App { | |
| public App(String name) { | |
| System.out.println(name + "'s constructor called"); | |
| } | |
| static { | |
| System.out.println("static initializer called"); | |
| } | |
| { | |
| System.out.println("instance initializer called"); | |
| } | |
| static { | |
| System.out.println("static initializer2 called"); | |
| } | |
| { | |
| System.out.println("instance initializer2 called"); | |
| } | |
| public static void main(String[] args) { | |
| new App("one"); | |
| new App("two"); | |
| } | |
| } | |
| // Output: | |
| static initializer called | |
| static initializer2 called | |
| instance initializer called | |
| instance initializer2 called | |
| one's constructor called | |
| instance initializer called | |
| instance initializer2 called | |
| two's constructor called |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment