zoukankan      html  css  js  c++  java
  • 11.13第十二次

    package Z;
    
    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();
        }
        @Override
        public String toString() {
            return "Person [name=" + name + ", age=" + age + "]";
        }
        public abstract String speak();
    }
    package Z;
    
    public class Student extends Person{
        private float score;
        
        public Student(String name, int age, float score) {
            super(name, age);
            this.setScore(score);
        }
        @Override
        public String speak() {
            return "学生说:我叫"+super.getName()+" "+super.getAge()+"岁 "+this.score+"分";
        }
        public float getScore() {
            return score;
        }
        public void setScore(float score) {
            this.score = score;
        }
    }
    package Z;
    
    public class Worker extends Person {
        private float salary;
        
        public Worker(String name, int age, float salary) {
            super(name, age);
            this.setSalary(salary);
        }
        @Override 
        public String speak() {
            return "工人说:我叫"+super.getName()+" "+super.getAge()+"岁 "+this.salary+"元";
        }
        public float getSalary() {
            return salary;
        }
        public void setSalary(float salary) {
            this.salary = salary;
        }
    }
    package Z;
    
    public class DemoStudentWorker {
    
        public static void main(String[] args) {
            Person student=new Student("AAA",16, 78f);
            Person worker=new Worker("BBB",34, 6500f);
            print(student.speak());
            print(worker.speak());
        }
        private static void print(String speak) {
            System.out.println(speak);
        }
    }

  • 相关阅读:
    防简单攻击iptables策略
    Iptables 防火墙常用配置
    9个常用iptables配置实例
    NFS服务的端口分配
    docker参数--restart=always的作用
    nginx的proxy_pass路径转发规则最后带/问题
    查看tomcat进程启动了多少个线程
    Tomcat 普通用户启动
    SSH远程执行脚本tomcat未启动
    mysql 前缀索引
  • 原文地址:https://www.cnblogs.com/woof95610/p/7860246.html
Copyright © 2011-2022 走看看