💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
![](https://box.kancloud.cn/daa2b5998f759ee3c1e497eaf39cb8b2_798x279.png) ~~~ package obj.a7; class Student{ private String name; private int age; private char sex; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public char getSex() { return sex; } public void setSex(char sex) { if(sex=='男'||sex=='女'){ this.sex = sex; }else{ System.out.println("请输入正确的性别格式"); } } } public class Test { public static void main(String[] args){ Student s=new Student(); s.setSex('男'); System.out.println(s.getSex()); } } ~~~