class Age {
public void setAge(int age) throws Exception{
if (age < 12 && age > 0){
System.out.println("This is a child");
}else if(age >= 18){
System.out.println("This is a adult");
}else if(age >=12 && age < 18){
System.out.println("This is a youth");
}else{
Exception e = new Exception("The age can't be negative number");
throw e;
}
}
}
throw and throws
最新推荐文章于 2022-04-19 23:42:04 发布