• 12


    package cty;

    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();
    }

    packagecty;
    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 "mingzi"+super.getName()+" "+super.getAge()+"sui "+this.score+"fen";
    }
    public float getScore() {
    return score;
    }
    public void setScore(float score) {
    this.score = score;
    }
    }

    package cty;

    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 "mingzi"+super.getName()+" "+super.getAge()+"sui"+this.salary+"yuan";

    }
    public float getSalary() {
    return salary;
    }
    public void setSalary(float salary) {
    this.salary = salary;
    }
    }

    package cty;

    public class DemoStudentWorker {

    public static void main(String[] args) {
    Person student=new Student("XX",3, 90.5f);
    Worker worker=new Worker("XX",1, 8125.5f);
    print(student.speak());
    print(worker.speak());
    }
    private static void print(String speak) {
    System.out.println(speak);
    }
    }

  • 相关阅读:
    QT多个UI文件加入一个项目
    【Go语言】学习资料
    MVC如何在Pipeline中接管请求的?
    ASP.NET MVC路由(5)
    C# dll 事件执行 js 回调函数
    初识Identity
    SpringMVC拦截器
    UrlRouting的理解
    ASP.NET MVC路由
    ASP.NET MVC Module
  • 原文地址:https://www.cnblogs.com/Archon-Cty/p/7865725.html
Copyright © 2020-2023  润新知