Skip to content

Instantly share code, notes, and snippets.

@thergbway
Created March 14, 2018 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thergbway/a329d1d59e533be5ca15e27cb8e90b77 to your computer and use it in GitHub Desktop.
Save thergbway/a329d1d59e533be5ca15e27cb8e90b77 to your computer and use it in GitHub Desktop.
Java init order
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