创建对象内存分析
作者:互联网
创建对象内存分析
Application.java
package com.oop;
import com.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);
Pet cat = new Pet();
}
}
Pet.java 模板
package com.oop.demo03;
public class Pet {
public String name;//默认为null
public int age;//默认为0
//无参构造
public void shout(){
System.out.println("叫了一声");
}
}
标签:分析,System,oop,Pet,dog,创建对象,内存,public,out 来源: https://www.cnblogs.com/kazesan/p/16204986.html