当前位置:网站首页>类加载内存分析

类加载内存分析

2022-06-22 06:10:00 酷小亚

Java内存分析

在这里插入图片描述

了解:类的加载过程

在这里插入图片描述

类的加载与ClassLoader的理解

在这里插入图片描述

下面放两个不同的代码,分别看下代码效果图,以作分析:

public class Demo7 {
    
    public static void main(String[] args) {
    
        A a = new A();
        System.out.println(A.m);
          /** * 1、加载到内存,会产生一个类class对象 * 2、链接,链接结束后 m = 0 * 3、初始化 * <clinit>(){ * System.out.print("A类静态代码块初始化"); * m = 100; * m = 300; * } * m = 300 */
    }
}
class A {
    
	
    static int m = 100;
    static {
    
        System.out.println("A类静态代码块初始化");
        m = 300;
    }

    public A(){
    
        System.out.println("A类的无参构造初始化");
    }

}

在这里插入图片描述

public class Demo7 {
    
    public static void main(String[] args) {
    
        A a = new A();
        System.out.println(A.m);
         /** * 1、加载到内存,会产生一个类class对象 * 2、链接,链接结束后 m = 0 * 3、初始化 * <clinit>(){ * System.out.print("A类静态代码块初始化"); * m = 300; * m = 100; * } * m = 100 */
    }
}
class A {
    
	//打印结果为:100
    static {
    
        System.out.println("A类静态代码块初始化");
        m = 300;
    }
	 static int m = 100;
	 
    public A(){
    
        System.out.println("A类的无参构造初始化");
    }

}

在这里插入图片描述

原网站

版权声明
本文为[酷小亚]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_45737330/article/details/125188112