package ctgu.java; public class TestPerson { public static void main(String[] args) { Person p = new Person(); p.steAge(120); //p.steAge(150); System.out.println(p.getAge()); } } class Person{ private int age ; public int getAge(){ return age ; } public void steAge(int a){ if(a > 0&& a <=130){ age = a; }else{ //System.out.println("你输入的数据有误"); throw new RuntimeException("你输入的数据有误!"); } } }
时间: 2024-10-28 06:20:59