public class homework008{
public static void main(String[] args) {
Dog dog = new Dog("tom","黄色",4);
dog.show();
}
}
class Dog{
String name;
String color;
int age;
public Dog(String name,String color,int age){
this.name = name;
this.color = color;
this.age = age;
}
public void show(){
System.out.println("——————信息——————");
System.out.println(this.name + "\t" + this.color + "\t" + this.age);
}
}
设计一个dog类 有名字、颜色和年龄属性,定义输出方法show()显示其信息。 并创建对象,进行测试
最新推荐文章于 2022-10-28 19:43:01 发布