Created
November 7, 2018 18:37
-
-
Save aploskov/613de0503676a2fc8a21f73801a95a17 to your computer and use it in GitHub Desktop.
Initialization 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.example; | |
interface Hello { | |
void hello(); | |
} | |
class A implements Hello { | |
static { | |
System.out.println("Static init A"); | |
} | |
{ | |
System.out.println("Init A"); | |
} | |
A() { | |
System.out.println("Construct A"); | |
} | |
{ | |
System.out.println("Second init A"); | |
} | |
static { | |
System.out.println("Second static init A"); | |
} | |
public void hello() { | |
System.out.println("Hello A"); | |
} | |
} | |
class B extends A { | |
static { | |
System.out.println("Static init B"); | |
} | |
{ | |
System.out.println("Init B"); | |
} | |
B() { | |
System.out.println("Construct B"); | |
} | |
{ | |
System.out.println("Second init B"); | |
} | |
static { | |
System.out.println("Second static init B"); | |
} | |
public void hello() { | |
super.hello(); | |
System.out.println("Hello B"); | |
} | |
} | |
public class Main { | |
public static void main(String[] args) { | |
Hello b = new B(); | |
b.hello(); | |
} | |
} |
Author
aploskov
commented
Nov 7, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment