ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
计一个Dog类,有名字、颜色、年龄等属性,定义构造方法来初始化类的这些属性,定义方法输出dog信息,编写程序使用Dog类。 ```java //狗类 public class Dog{ private String name; private String color; private int age; public Dog() {} public Dog(String name,String color,int age) { this.name=name; this.color=color; this.age=age; } //setter、getter方法略写 public String getInfo() { return "姓名:"+this.name+"、颜色:"+this.color+"、年龄:"+this.age; } } //测试类 public class Test { public static void main(String args[]) { Dog dog=new Dog("小胖","黄棕色",6); System.out.println(dog.getInfo()); } } ```