创建对象的内存分析
代码示例
- 创建一个Pet类
public class Pet {
String name;
int age;
public void shot(){
System.out.println("叫了一声");
}
}
- 实例化对象
public class Demo {
public static void main(String[] args) {
Pet dog = new Pet();
dog.name = "旺财";
dog.age = 1;
dog.shot();
System.out.println(dog.name);
System.out.println(dog.age);
}
}