the fist blood of java-eclipse 哈哈哈哈 封装的运用

时间:2022-11-03 15:56:10
class Student {
    private int id;
    public String name;
    public String sex;
    private int score;
    public void setId(int id) {
        this.id = id;
    }
    public int getId() {
        return id;
    }
    public void setScore(int score) {
        this.score = score;
    }
    public int getScore() {
        return score;
    }
    public void study() {
        System.out.println("好好学习,天天向上!");
    }
    public void exam() {
        System.out.println("考试不努力,毛大做兄弟!");
    }
}
public class Dome1 {
    public static void main(String[] args) {
        Student s= new Student();
        s.name="狗蛋";
        s.sex="男";
        s.setId(10086);
        s.setScore(450);
        System.out.println("姓名:"+s.name);
        System.out.println("性别:"+s.sex);
        System.out.println("学号:"+s.getId());
        System.out.println("最后一次模考成绩:"+s.getScore());
        s.study();
        s.exam();
    }
}