jvm虚拟机--jvm加载类的先后顺序

jvm虚拟机--jvm加载类的先后顺序

--java代码执行顺序

package com.bdqn.javascriptengine;
/**
 * 初始化类的先后顺序
 * @author OU
 *
 */
public class Demo01 {
     
    static {
        System.out.println("main 方法的静态代码块");
    }
     
  public static void main(String[] args) {
      System.out.println("main 的主方法"); 
     //主动引用
      A a=new A();
      System.out.println(a.length);
      //Class.forName("");
      //被动引用 ,不会初始化A类
      // A.MAX;
      //A[] a=new A[10];
      //不会初始化B类
      System.out.println(B.length);
  }
}

class B extends A{
   static{
       System.out.println("B 类的静态方法");
   }    
}

class A extends C{
    public static int length=100;
    public static final int MAX=200;
    
    static{
        System.out.println("A 类的静态代码块");
        length=300;
    }
    public static void test(){
        
        System.out.println("A 类的静态方法");
    }
}

class C{
    
    static{
        
        System.out.println("C 类的静态方法");
    }
    
    
    
}
demo1

相关文章:

  • 2021-04-24
  • 2021-04-30
  • 2021-12-13
  • 2021-10-06
  • 2022-12-23
  • 2021-12-06
  • 2021-09-07
  • 2021-04-10
猜你喜欢
  • 2021-11-26
  • 2021-08-07
  • 2021-05-04
  • 2021-10-14
  • 2022-12-23
  • 2022-12-23
  • 2021-11-12
相关资源
相似解决方案