static块与代码执行循序

xiaoxiao2025-12-11  10

class Person{ public String name = "liuqing"; Person(){ System.out.println("person construct"); }}class StaticTest { /** 构造方法*/ public StaticTest() { System.out.println("构造函数被执行了!"); } static Person person = new Person(); /** 静态代码快*/ static { System.out.println("静态代码块被执行了!"); //show(); } /** 静态方法*/ public static void show(){ System.out.println("静态方法被执行了!"); } } public class teststatic { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub StaticTest st = new StaticTest(); }} 结果: person construct 静态代码块被执行了! 构造函数被执行了!
转载请注明原文地址: https://www.6miu.com/read-5040707.html

最新回复(0)