package oop.demo01; public class Pet { public String name; public int age; //无参构造 public void shout(){ System.out.println("叫了一声"); } } ------------------------------------------------------- package oop.demo01; //一个项目应该只存在一个main方法 public class Application { public static void main(String[] args) { Pet dog = new Pet(); dog.name="旺财"; dog.age = 3; dog.shout(); System.out.println(dog.name); System.out.println(dog.age); Pet cat = new Pet(); } }
搜索
复制