JAVA简单问题
设计一个Dog类,有名字、颜色和年龄属性,定义构造方法初始化这些属性,定义输出方法show()显示其信息。编写应用程序使用Dog类。...
设计一个Dog类,有名字、颜色和年龄属性,定义构造方法初始化这些属性,定义输出方法show()显示其信息。编写应用程序使用Dog类。
展开
2个回答
展开全部
public class TestDog {
public static void main(String[] args){
Dog dog = new Dog("wangcai","black",5);
dog.show();
}
}
class Dog{
String name;
String color;
int age ;
public Dog(String name,String color,int age){
this.age = age;
this.name = name;
this.color = color;
}
public void show(){
System.out.print("名字是 : "+this.name+", 颜色是:"+this.color+",年龄是"+this.age);
}
}
结果为:
名字是 : wangcai, 颜色是:black,年龄是5
public static void main(String[] args){
Dog dog = new Dog("wangcai","black",5);
dog.show();
}
}
class Dog{
String name;
String color;
int age ;
public Dog(String name,String color,int age){
this.age = age;
this.name = name;
this.color = color;
}
public void show(){
System.out.print("名字是 : "+this.name+", 颜色是:"+this.color+",年龄是"+this.age);
}
}
结果为:
名字是 : wangcai, 颜色是:black,年龄是5
展开全部
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("name is " + this.name + " " + "color is "
+ this.color + " " + "age is " + this.age);
}
}
public class Test {
public static void main(String[] args) {
Dog d = new Dog("nihao", "red", 21);
d.show();
}
}
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("name is " + this.name + " " + "color is "
+ this.color + " " + "age is " + this.age);
}
}
public class Test {
public static void main(String[] args) {
Dog d = new Dog("nihao", "red", 21);
d.show();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询