• 11.14 (成绩,工资)第12次作业


    package cn.wzx.www;
    
    public abstract class Person {
        private String name;
        private int age;
        public Person(String name,int age){
            this.name=name;
            this.age=age;
            
        }
        public Person() {
            super();
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public abstract String speak();
        public int getAge() {
            return age;
        }
        public void setAge(int age) {
            this.age = age;
        }
    }
    package cn.wzx.www;
    
    public class Student extends Person {
        private float score;
        public Student(){
            
        }
        public Student(String name,int age,float score) {
            // TODO 自动生成的构造函数存根
            super(name,age);
            this.score=score;
            //this.setScore(score);
        }
        @Override
        public String speak() {
            // TODO 自动生成的方法存根
            return "我是"+super.getName()+", 我"+super.getAge()+"岁了,"+"我的成绩是"+this.score;
        }
        public float getScore() {
            return score;
        }
        public void setScore(float score) {
            this.score = score;
        }
        
    
    }
    package cn.wzx.www;
    
    public class Worker extends Person {
        private float rewards;
        public Worker(String name, int age, float rewards) {
            // TODO 自动生成的构造函数存根
            super(name, age);
            this.rewards=rewards;
        }
        
        @Override
        public String speak() {
            // TODO 自动生成的方法存根
            return "我是"+super.getName()+", 我"+super.getAge()+"岁了,"+"我的工资是"+this.rewards;
        }
        public float getRewards() {
            return rewards;
        }
        public void setRewards(float rewards) {
            this.rewards = rewards;
        }
        
        
    
    }
    package cn.wzx.www;
    
    public class DemoWoSt {
    
        public static void main(String[] args) {
            // TODO 自动生成的方法存根
            Person student =new Student("张三",18,59.0f);
            Person worker =new Worker("李四",30,3600.8f);
            print(student.speak());
            print(worker.speak());
    
        }
         private static void print(String speak) {
                System.out.println(speak);
            }
    
    
    }

  • 相关阅读:
    Springboot html映射
    table 合并单元格
    Idea中Spring Boot 启动出错
    Modal模态框scrolltop保留上次位移的解决方案
    8、如何实现浏览器的前进、后退操作?
    html中table并排展示
    两个有序的链表的合并
    7、链表(下):如何轻松写出正确的链表代码?
    2018.10.12
    c语言关键字:const
  • 原文地址:https://www.cnblogs.com/jasonzj/p/7834309.html
Copyright © 2020-2023  润新知