创建对象的内存分析

创建对象的内存分析

 

package com.zishi.oop.demo03;
   
import com.zishi.oop.demo03.Pet;

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);
  }
}

 

package com.zishi.oop.demo03;

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


   //无参构造

   public void shout(){
       System.out.println("叫了一声");
  }
}

 

 

image-20210726124832913

 

posted @ 2021-07-26 12:55  子时未临  阅读(57)  评论(0编辑  收藏  举报