Created
March 14, 2018 09:36
-
-
Save thergbway/a329d1d59e533be5ca15e27cb8e90b77 to your computer and use it in GitHub Desktop.
Java init order
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
package com.thergbway; | |
import static com.thergbway.Main.getNumber; | |
class One { | |
static String a = getNumber(1); | |
static {getNumber(2);} | |
One() {getNumber(9);} | |
{getNumber(7);} | |
static Two two = new Two(); | |
static {getNumber(5);} | |
static String b = getNumber(6); | |
{getNumber(8);} | |
} | |
class Two { | |
static String c = getNumber(3); | |
Two() {getNumber(4);} | |
} | |
public class Main { | |
public static String getNumber(int number) { | |
System.out.println(number); | |
return String.valueOf(number); | |
} | |
//prints 1 2 3 4 5 6 7 8 9 | |
public static void main(String[] args) {new One();} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment