2022-12-11 00:13:07
public class Pet { String name; int age; public void shout(){ System.out.println("叫了一声!"); } } public class Application { public static void main(String[] args) { Pet dog = new Pet(); Pet cat = new Pet(); dog.name="旺财"; dog.age=3; System.out.println(dog.name); System.out.println(dog.age); System.out.println(cat.name); System.out.println(cat.age); dog.shout(); } }
栈:存用来存储局部变量和方法调用
堆: 存用来存储Java中的对象
标签:System,JAVA,Pet,dog,创建对象,println,基础知识,public,out From: https://www.cnblogs.com/ZLey/p/16972707.html