62,633
社区成员
发帖
与我相关
我的任务
分享
public class Student {
private String name; //姓名
private String sex; //性别
private int age; //年龄
public Student(String name, String sex, int age) { //构造方法
this.name = name;
this.sex = sex;
this.age = age;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public void setName(String name) {
this.name = name;
}
public void outInfo(){ //输出 学生信息
System.out.println("姓名:"+name+" 性别:"+sex+" 年龄:"+age);
}
public void fun(){ //判断年龄是否小于20
if(age<20){
outInfo();
}
}
public static void main(String args[]) {
Student stu1=new Student("小钱","男",22);
Student stu2=new Student("小五","女",21);
stu1.age++; //年龄加1
stu2.age++; //年龄加1
stu1.fun();
stu2.fun();
}
}