创建对象内存分析

创建对象内存分析

代码实现:

1、

public class Application {
    public static void main(String[] args) {

        Pet dog = new Pet();
        dog.name = "旺财";
        dog.age = 3;
        dog.shout();
        System.out.println(dog.name);
        System.out.println(dog.age);

        Pet cat = new Pet();
        
    }
}

public class Pet {
    public String name;
    public int age;

    //无参构造

    public void shout(){
        System.out.println("叫了一声");
    }
}
posted @ 2020-07-11 00:40  小卢传  阅读(109)  评论(0编辑  收藏  举报