当前位置: 首页 > 工具软件 > Fist > 使用案例 >

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

陈成济
2023-12-01
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();
    }

}

转载于:https://www.cnblogs.com/0929-luoyang/p/10793517.html

 类似资料: