码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2019-04-29 23:43:22      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:封装   java   div   lips   public   成绩   []   好好学习   out   

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

}

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

标签:封装   java   div   lips   public   成绩   []   好好学习   out   

原文地址:https://www.cnblogs.com/0929-luoyang/p/10793517.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!