Java Private如何使用

Java Private如何使用

 

 

 

package com.geekeryi0730;

public class Student {
    String name;
    private int age;

    public void setAge(int a) {
        if (0<a&&a<120){
            age = a;
        }else {
            System.out.println("你TM给老子瞎JB输");
        }

    }

    public int getAge() {
        return age;
    }

    public void show() {
        System.out.println(age + "," + name);
    }
}

 

 

package com.geekeryi0730;

public class StudentDemo {
    public static void main(String[] args) {
        Student s1 = new Student();
        System.out.println(s1.getAge());
        s1.setAge(999);
        s1.name="瓜皮";
        s1.show();
    }
}

  

 

posted @ 2020-07-30 17:59  极客易先生  阅读(1243)  评论(0编辑  收藏  举报