Skip to content

Instantly share code, notes, and snippets.

@Harshal96
Last active July 19, 2019 03:58
Show Gist options
  • Select an option

  • Save Harshal96/f040c27957d3c9313c58731f21432fe5 to your computer and use it in GitHub Desktop.

Select an option

Save Harshal96/f040c27957d3c9313c58731f21432fe5 to your computer and use it in GitHub Desktop.
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