java 对象内存分析
对象内存分析
1,新建Application类,作为程序的入口
package oop;
import oop.demo03.Pet;
public class Application {
public static void main(String[] args) {
Pet pig = new Pet();
pig.name="小朱佩奇";
pig.age=3;
pig.shout();
System.out.println("name:"+pig.name);
System.out.println("age:"+pig.age);
}
}
2,新建Pet类
package oop.demo03;
/*
创建对象内存分析
*/
//宠物类
public class Pet {
public String name;
public int age;
public void shout() {
System.out.println("宠物叫了!!");
}
}