private String name; //定义“水果名称”
2023-06-12 本文已影响0人
哈迪斯Java
public class Fruit //创建一个Fruit类
{
private String name; //定义“水果名称”
private float price; //定义“水果价格”
private float weight; //定义“水果重量”
public String getName() //获得“水果名称”
{
return name;
}
public void setName(String name) //设置“水果名称”
{
this.name = name;
}
public float getPrice() //获得“水果价格”
{
return price;
}
public void setPrice(float price) //设置“水果价格”
{
this.price = price;
}
public float getWeight() //获得“水果重量”
{
return weight;
}
public void setWeight(float weight) //设置“水果重量”
{
this.weight = weight;
}
}