class Student
{
private String number;
private String banji;
private String name;
private String sex;
private int age;
Student(String number,String banji,String name,String sex,int age)
{
this.number=number;
this.banji=banji;
this.name=name;
this.sex=sex;
this.age=age;
}
public void getAge()
{
System.out.println(age);
}
boolean setStudentAge(int newAge)
{
if(newAge>=1&&newAge<=100)
{
this.age=newAge;
return true;
}
System.out.println("非法学生年龄");
return false;
}
}
class Test11
{
public static void main(String[] args)
{
Student st1=new Student("20150304","1班","张三","男",25);
Student st2=new Student("20150305","2班","李四","女",23);
Student st3=new Student("20150307","1班","王五","男",24);
Student st4=new Student("20150301","3班","小敏","女",26);
boolean b=st1.setStudentAge(51);
System.out.println("b="+b);
st1.getAge();
boolean b1=st2.setStudentAge(-23);
System.out.println("b1="+b1);
st2.getAge();
}
}
|