package September;
public class Animal {
double weight;
public double getWeight() {
return weight;
}
public void setWeight(double weight)throws Exception {
if (weight<2||weight>100) {
throw new Exception("你输入体重不符合");
}
this.weight=weight;
}
}
package September;
public class TestAnimal {
public static void main(String[] args) {
Animal a=new Animal();
try {
a.setWeight(500);
System.out.println(a.getWeight());
} catch (Exception e) {
String string=e.getMessage();
System.out.println(string);
}
}
}
916-2
最新推荐文章于 2022-05-01 00:06:41 发布