编写Java应用程序,定义Animal类,此类中有动物的属性:名称 name,腿的数量legs,统计动物的数量 count;方法:设置动物腿数量的方法 void setLegs(),获得腿数量的方法 getLegs(),设置动物名称的方法 setKind(),获得动物名称的方法 getKind(),获得动物数量的方法 getCount()。定义Fish类,是Animal类的子类,统计鱼的数量 count,获得鱼数量的方法 getCount()。定义Tiger类,是Animal类的子类,统计老虎的数量 count,获得老虎数量的方法 getCount()。定义SouthEastTiger类,是Tiger类的子类,统计老虎的数量 count,获得老虎数量的方法 getCount()。
时间: 2024-02-13 12:04:20 浏览: 16
好的,以下是Animal类、Fish类、Tiger类和SouthEastTiger类的Java代码实现:
Animal类:
```java
public class Animal {
private String name;
private int legs;
private static int count;
public void setLegs(int legs) {
this.legs = legs;
}
public int getLegs() {
return legs;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public static int getCount() {
return count;
}
public Animal() {
count++;
}
}
```
Fish类:
```java
public class Fish extends Animal {
private static int count;
public static int getCount() {
return count;
}
public Fish() {
count++;
}
}
```
Tiger类:
```java
public class Tiger extends Animal {
private static int count;
public static int getCount() {
return count;
}
public Tiger() {
count++;
}
}
```
SouthEastTiger类:
```java
public class SouthEastTiger extends Tiger {
private static int count;
public static int getCount() {
return count;
}
public SouthEastTiger() {
count++;
}
}
```
以上代码实现了Animal类、Fish类、Tiger类和SouthEastTiger类的属性和方法要求,其中静态变量count用于统计不同类别动物的数量,每次创建一个对象都会将count加一。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)