class StudentDemo
{
public static void main(String[] args)
{
Student stu = new Student();
stu.name ="李芳";
stu.setAge(-20);
stu.getAge();
stu.introduce ();
}
}
class Student
{
private int age ;
String name ;
public void setAge(int stuage)
{
if (stuage<0)
{
System.out.println("年龄不合法");
}
else
age=stuage;
}
public int getAge()
{
return age;
}
void introduce()
{
System.out.println("她的名字是"+name+",今年"+age+"岁");
}
}
|
|