package day31; public class Pet { String name; int age; public void shout(){ System.out.println("叫了一声"); } }
package day31; public class Application { public static void main(String[] args) { Pet cat = new Pet(); cat.name="肥波"; cat.age=2; cat.shout(); System.out.println(cat.name); System.out.println(cat.age); } }
Java中会把方法区的变量加载到堆里面的对象上