markdown static,block,java,syntax

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown static,block,java,syntax相关的知识,希望对你有一定的参考价值。

## Static Block In Java

- used for initializing static variable
- execute when class loaded in memory
- class can have multiple static block
- multiple static block execute in order
- execute before constrctor
  - constructor 是关联对象的, static 是关联class 的必然要比构造先执行

```java
// sample class
package staticblock;

public class StaticBlock {
    static int num;
    static String name;

    static {
        System.out.println("Call static block");
    }

    static {
        System.out.println("Assign value to num");
        num = 1;
    }

    static {
        System.out.println("Assign value to name");
        name = "jack";
    }

    public StaticBlock() {

        System.out.println("Call constructor");
    }
}

// test class
package staticblock;

public class StaticBlockTest {
    public static void main(String[] args) {
        StaticBlock sb = new StaticBlock();
    }
}
```

**Console Output**

```bash
Call static block
Assign value to num
Assign value to name
Call constructor

Process finished with exit code 0

```

以上是关于markdown static,block,java,syntax的主要内容,如果未能解决你的问题,请参考以下文章

为啥我会收到 Invalid block tag: 'static' 错误?

PHP Magento - PHTML页面中的Echo Static Block

java static block

Math Block for Markdown [For Typora]

Math Block for Markdown [For Typora]

markdown 64位主机上的quasselcore-static