有一个java的编程题。编写一个DOG类,它有名字(name)颜色(color)和年龄(age)三个属性
有一个java的编程题。编写一个DOG类,它有名字(name)颜色(color)和年龄(age)三个属性,定义构造属性,定义成员方法show()输出信息。便携使用Dog的...
有一个java的编程题。编写一个DOG类,它有名字(name)颜色(color)和年龄(age)三个属性,定义构造属性,定义成员方法show( )输出信息。便携使用Dog的应用程序,类名为Dog Text,只有main( )方法,用来测试Dog类,产生2个Dog队形,并输出信息
展开
1个回答
2011-05-09
展开全部
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;
}
public void show() {
System.out.println("name:" + this.name);
System.out.println("color:" + this.color);
System.out.println("age:" + this.age);
}
}
DogTest.java
public class DogTest {
public static void main(String[] args) {
Dog dog1 = new Dog("大黑", "黑", 2);
Dog dog2 = new Dog("小白", "白", 1);
dog1.show();
dog2.show();
}
}
// try...
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;
}
public void show() {
System.out.println("name:" + this.name);
System.out.println("color:" + this.color);
System.out.println("age:" + this.age);
}
}
DogTest.java
public class DogTest {
public static void main(String[] args) {
Dog dog1 = new Dog("大黑", "黑", 2);
Dog dog2 = new Dog("小白", "白", 1);
dog1.show();
dog2.show();
}
}
// try...
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询