五、创建对象内存分析
内存分析图
宠物类
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(喵喵喵); }