Created
March 11, 2015 11:06
-
-
Save sergiilagutin/b4b470e9f1db835e6a6b to your computer and use it in GitHub Desktop.
Java creation of new object
This file contains 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
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