zoukankan      html  css  js  c++  java
  • JAVA练习10

    练习12

     
    复制代码
    package cn.ch.w;
    
    public abstract class Person {
        private String name;
        private int age;
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public int getAge() {
            return age;
        }
        public void setAge(int age) {
            this.age = age;
        }
        public Person(String name, int age) {
            this.name = name;
            this.age = age;
        }
        public Person() {
            super();
        }
        public String toString() {
            return "Person [name=" + name + ", age=" + age + "]";
        }
        public abstract String speak();
    }
    复制代码
    复制代码
    package cn.ch.w;
    public class Student extends Person{
        private float score;
        
        public Student(String name, int age, float score) {
            super(name, age);
            this.setScore(score);
        }
        public String speak() {
            return "学生说-->我的姓名:"+super.getName()+" "+super.getAge()+"岁 "+this.score+"分";
        }
        public float getScore() {
            return score;
        }
        public void setScore(float score) {
            this.score = score;
        }
    }
    复制代码
    复制代码
    package cn.ch.w;
    
    public class Worker extends Person {
        private float salary;
        
        public Worker(String name, int age, float salary) {
            super(name,age);
            this.setSalary(salary);
        }
        public String speak() {
            return "工人说 -->我的姓名:"+super.getName()+" "+super.getAge()+"岁 "+this.salary+"元";
    
        }
        public float getSalary() {
            return salary;
        }
        public void setSalary(float salary) {
            this.salary = salary;
        }
    }
    复制代码
    复制代码
    package cn.ch.w;
    
    public class DemoStudentWorker {
        
    
            public static void main(String[] args) {
                Person student=new Student("香菇",3, 90.5f);
                Worker worker=new Worker("草菇",1, 8125.5f);
                print(student.speak());
                print(worker.speak());
            }
            private static void print(String speak) {
                System.out.println(speak);
            }
        }
    复制代码

  • 相关阅读:
    适配器
    策略
    oom的各种情况
    sql 优化//TODO
    聚簇索引和非聚簇索引
    Shard内部原理
    es集群健康状态
    转载 R语言颜色基础设置
    三维数据的展示
    python 文件保存 出错
  • 原文地址:https://www.cnblogs.com/qxc81518/p/7865193.html
Copyright © 2011-2022 走看看