写出以下代码的测试类public abstract class Tree { private int id; private String category; private String location; private String plantDate; private double height; private double crownDiameter; private double trunkDiameter; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getCategory() { return category; } public void setCategory(String category) { this.category = category; } public String getLocation() { return location; } public void setLocation(String location) { this.location = location; } public String getPlantDate() { return plantDate; } public void setPlantDate(String plantDate) { this.plantDate = plantDate; } public double getHeight() { return height; } public void setHeight(double height) { this.height = height; } public double getCrownDiameter() { return crownDiameter; } public void setCrownDiameter(double crownDiameter) { this.crownDiameter = crownDiameter; } public double getTrunkDiameter() { return trunkDiameter; } public void setTrunkDiameter(double trunkDiameter) { this.trunkDiameter = trunkDiameter; } }
时间: 2024-02-14 14:17:07 浏览: 24
以下是Tree类的测试类:
```
public class TreeTest {
public static void main(String[] args) {
Tree tree = new Tree() {
// 匿名内部类实现抽象类
};
// 设置树的属性
tree.setId(1);
tree.setCategory("松树");
tree.setLocation("北京");
tree.setPlantDate("2021-01-01");
tree.setHeight(10);
tree.setCrownDiameter(5);
tree.setTrunkDiameter(1);
// 获取树的属性
System.out.println("树的ID:" + tree.getId());
System.out.println("树的种类:" + tree.getCategory());
System.out.println("树的位置:" + tree.getLocation());
System.out.println("树的种植日期:" + tree.getPlantDate());
System.out.println("树的高度:" + tree.getHeight());
System.out.println("树的冠幅直径:" + tree.getCrownDiameter());
System.out.println("树的树干直径:" + tree.getTrunkDiameter());
}
}
```