- package myooptest;
- public class Person {
- private int age;
- public int getAge() {
- return age;
- }
- public void setAge(int a) {
- if(a>0 && a<130) //判断接收进来的a ,而不是判断age ,
- age = a;
- else
- System.out.println("nono");
- }
- public void speak() {
- System.out.println("age:"+age);
- }
-
- }
复制代码 |