zoukankan      html  css  js  c++  java
  • 静态块 非静态块 构造器 执行的顺序

    顺序:

    父类静态块 > 子类静态块 > 父类 非静态块 > 父类构造器 >  子类非静态块 > 子类构造器。

    Example:

    public class BlockParentTest {
    
        public BlockParentTest() {
            System.out.println("parent constructor");
        }
        
        static {
            System.out.println("parent static block");
        }
        
        {
            System.out.println("parent block");
        }
    }
    public class BlockTest extends BlockParentTest{
    
        public BlockTest() {
            System.out.println("child constructor");
        }
        
        {
            System.out.println("child block");
        }
        
        static {
            System.out.println("child static block");
        }
        public static void main(String[] args) {
            new BlockTest();
        }
    }

    Result:

    parent static block
    child static block
    parent block
    parent constructor
    child block
    child constructor

  • 相关阅读:
    2015多校.Zero Escape (dp减枝 && 滚动数组)
    UVa-11809
    UVa-1588 Kickdown
    UVa-1587
    UVa-10340
    UVa-202
    UVa-1368
    UVa-232 Crossword Answers
    UVa-227
    UVa-455 Periodic Strings
  • 原文地址:https://www.cnblogs.com/mid-wk/p/7159460.html
Copyright © 2011-2022 走看看