Skip to content

Instantly share code, notes, and snippets.

@sergiilagutin
Created March 11, 2015 11:06
Show Gist options
  • Save sergiilagutin/b4b470e9f1db835e6a6b to your computer and use it in GitHub Desktop.
Save sergiilagutin/b4b470e9f1db835e6a6b to your computer and use it in GitHub Desktop.
Java creation of new object
class A {
static {
System.out.println("static A");
}
static {
System.out.println("static A2");
}
public A() {
System.out.println("<init> A");
}
static {
System.out.println("static A3");
}
}
class B extends A {
static {
System.out.println("static B");
}
private String name = buildName();
private static String buildName(){
System.out.println("field B");
return "name";
}
public B() {
super();
System.out.println("<init> B");
}
}
class Runner {
public static void main(String[] args) {
new B();
System.out.println("created 1st object");
new B();
System.out.println("created 2nd object");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment