CoreJava/exp3/Animal.java

33 lines
602 B
Java
Raw Normal View History

2024-05-09 09:10:51 +08:00
package exp3;
public class Animal {
//成员变量
String name;
int weight;
String color;
//无参构造
public Animal(){
this.weight = 2;
this.color = "黑色";
this.name = "Animal";
}
//全参构造
public Animal(String name,int weight, String color){
this.name = name;
this.color = color;
this.weight = weight;
}
//动作-行走
void walk(){
System.out.println(this.name+"行走...");
}
//动作-奔跑
void run(){
System.out.println(this.name+"奔跑...");
}
}