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);
}
}
}
05-06
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交