3条回答 默认 最新
- 咕泡-文泰 2021-07-19 04:21关注
public class Person {
public static void main(String[] args) throws Exception { Person person = new Person("张三","男",20); System.out.println(person) ; } private String name = ""; protected String gradel=""; int age = 0; public Person() { } public Person(String name, String gradel, int age) throws Exception { if (!("男".equals(gradel) || "女".equals(gradel))) { throw new Exception("性别只能是男或者女"); } if (age < 0 || age > 130) { throw new Exception("年龄超过范围"); } this.name = name; this.gradel = gradel; this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getGradel() { return gradel; } public void setGradel(String gradel) { this.gradel = gradel; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public String toString() { return "Person{" + "name='" + name + '\'' + ", gradel='" + gradel + '\'' + ", age=" + age + '}'; }
}
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 2无用 3
悬赏问题
- ¥15 帮我调试idea基于spring boot项目
- ¥15 es 7.17.20版本生成时间戳
- ¥15 wpf dategrid表头排序图标自定义
- ¥15 分析下图所示同步时序逻辑电路的逻辑功能。
- ¥15 halcon联合c#遇到了问题不能解决
- ¥15 xshell无法连接提示ssh服务器拒绝密码
- ¥15 AT89C52单片机C语言关于串口通信的位操作
- ¥20 需要步骤截图(标签-服务器|关键词-map)
- ¥50 gki vendor hook
- ¥15 灰狼算法和蚁群算法如何结合