class Student {
public static void main(String[] args) {
Student stu=new Student();
stu.setAge(20);
stu.setName("李磊");
stu.intruduce();
}
private String name;
private int age;
/*public String getName (){
return name;
}*/
public void setName(String stuName){
name=stuName;
}
/*public int getAge(){
return age;
}*/
public void setAge(int stuAge){
if (stuAge<0) {
System.out.println("shurucuowu ");
}else
age=stuAge;
}
public void intruduce(){
System.out.println("我叫"+name+",我"+age+"岁");
}
}
|
|