zoukankan      html  css  js  c++  java
  • JAVA学习日记30-0804

    今天学了什么

    用Person类设计Student类和Teacher类

    Person类:

    package person;

    public class Person {
    protected String name,sex;
    protected int age;

    public void setname(String name) {
    this.name=name;
    }
    public void setsex(String sex) {
    this.sex=sex;
    }
    public void setage(int age) {
    this.age=age;
    }
    public String getname() {
    return name;
    }
    public String getsex() {
    return sex;
    }
    public int getage() {
    return age;
    }

    }

    Student类:

    package person;

    public class Student extends Person {

    private String no,classno;
    private double score;
    public void setno(String no) {
    this.no=no;
    }
    public String getno() {
    return no;
    }
    public void setclassno(String classno) {
    this.classno=classno;
    }
    public String getclassno() {
    return classno;
    }
    public void setscore(double score) {
    this.score=score;
    }
    public double getscore() {
    return score;
    }


    }

    Teacher类:

    package person;

    public class Teacher extends Person {

    private String tno,object;
    private double wages;
    public void settno(String tno) {
    this.tno=tno;
    }
    public String gettno() {
    return tno;
    }
    public void setobject(String object) {
    this.object=object;
    }
    public String getobject() {
    return object;
    }
    public void setwages(double wages) {
    this.wages=wages;
    }
    public double getwages() {
    return wages;
    }
    }

    Show类:

    package person;

    public class Show {

    public static void main(String[] args) {
    Student s = new Student();
    s.setname("小明");
    s.setsex("男");
    s.setage(19);
    s.setno("20190001");
    s.setclassno("1905");
    s.setscore(86);
    System.out.println("-----学生-----");
    System.out.println("姓名:"+s.getname());
    System.out.println("性别:"+s.getsex());
    System.out.println("年龄:"+s.getage());
    System.out.println("学号:"+s.getno());
    System.out.println("班级:"+s.getclassno());
    System.out.println("成绩:"+s.getscore());
    System.out.println(" ");
    Teacher t = new Teacher();
    t.setname("张三");
    t.setsex("女");
    t.setage(46);
    t.settno("0006");
    t.setobject("java");
    t.setwages(8000);
    System.out.println("-----教师-----");
    System.out.println("姓名:"+t.getname());
    System.out.println("性别:"+t.getsex());
    System.out.println("年龄:"+t.getage());
    System.out.println("工号:"+t.gettno());
    System.out.println("科目:"+t.getobject());
    System.out.println("工资:"+t.getwages());

    }

    }

    运行截图:

     遇到的问

    明天计划

    练习面向对象题目

  • 相关阅读:
    计蒜客模拟赛D2T2 蒜头君的排序:区间逆序对(移动端点) + 树状数组
    计蒜客模拟赛D2T1 蒜头君的兔子:矩阵快速幂
    计蒜客模拟赛D1T2 蒜头君的树:树上节点之间最短距离和
    计蒜客模拟赛D1T1 蒜头君打地鼠:矩阵旋转+二维前缀和
    Cubieboard安装系统
    awk速查手册
    sed速查手册
    常用正则表达
    MySQL索引小记
    jQuery中attr和prop的区别
  • 原文地址:https://www.cnblogs.com/a8047/p/13433582.html
Copyright © 2011-2022 走看看