java-简述对象由表格组成

“一切皆对象,对象就是表格”,这句话比较绝对,在一般情况来说我们就可以这样的理解。
数据无处不在,而表格就是存储这些数据最常用的办法。打比方说某件物品的大小、型号、价格…这些最常见的数据,其实也都是表格中的每一个数据,如图所示:
在这里插入图片描述
图中是学生及学生成绩表格,包含学号、姓名、性别、各科成绩及总分,我们可以看作是类中的属性,动作则是类中的方法,如图所示:
在这里插入图片描述
要记得不同类型的使用方式,在这里姓名和性别使用了String字符串,其他比如学号,成绩等数字则使用了int类型。
这样一看,每个表格就是一个类,表格的标题,就是类中的属性,而方法则是每个学生对象都需要完成的事情。
代码如下

public class Student {
    int id ;
    String name ;
    String sex ;
    int chinese_score;
    int math_score;
    int english_score;
    int total_score;

    void fun(){
        System.out.println("7.30到校打卡晨读");
    }
    public Student(){}

    public Student(int id, String name, String sex, int chinese_score,
                   int math_score, int english_score, int total_score)
    {
        this.id = id;
        this.name = name;
        this.sex = sex;
        this.chinese_score = chinese_score;
        this.math_score = math_score;
        this.english_score = english_score;
        this.total_score = total_score;
    }

    @Override
    public String toString() {
        return "学号:"+id+"\t姓名:"+name+"\t性别:"+sex
                +"\t语文:"+chinese_score+"\t数学:"+math_score
                +"\t英语"+english_score +"\t总分:"+total_score;
    }

    public static void main(String[] args) {
        Student s1 = new Student(1,"甲","男",
                80,95,85,260);
        System.out.println(s1);
        s1.fun();
    }
}

运行结果:
在这里插入图片描述
由此可见,数据信息都可以表格的形式存在,表格可以看作一个类,类中的数据就是对象。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值