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

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();
    }

}
posted on 2019-04-29 23:25  18软工五班罗小杨  阅读(133)  评论(1编辑  收藏  举报