image.png

    1. package com.atguigu.exercise;
    2. public class PersonTest {
    3. public static void main(String[] args) {
    4. Person b = new Person();
    5. // b.getAge();
    6. b.setAge(12);
    7. }
    8. }
    9. class Person{
    10. private int age;
    11. public void setAge(int a){
    12. if(a<0 || a>130){
    13. System.out.println("输入的数据非法");
    14. }else{
    15. age = a;
    16. }
    17. System.out.println("年龄为:"+ age);
    18. }
    19. public int getAge(){
    20. return age;
    21. }