五、创建对象内存分析
作者:互联网
内存分析图
宠物类
public class Pet { String name; int age; void speak(String words){ System.out.println(words); } static void sayHi(){ System.out.println("Hi"); } }
测试类
public static void main(String[] args) { Pet dog = new Pet(); dog.name="小狗"; dog.age=2; dog.speak("汪汪汪"); Pet cat = new Pet(); cat.name="小狗"; cat.age=2; dog.speak("喵喵喵"); }
标签:分析,String,name,Pet,void,dog,创建对象,内存,speak 来源: https://www.cnblogs.com/epiphany8/p/16265201.html