33 lines
602 B
Java
33 lines
602 B
Java
|
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+"奔跑...");
|
||
|
}
|
||
|
}
|