• 第十二次作业


    package PJH;
    
    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 PJH;
    
    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 PJHJ;
    
    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 PJH;
    
    public class DemoStudentWorker {
    
        public static void main(String[] args) {
            Person student=new Student("旺财",3, 90.5f);
            Person worker=new Worker("小强",1, 8125.5f);
            print(student.speak());
            print(worker.speak());
        }
        private static void print(String speak) {
            System.out.println(speak);
        }
    }

  • 相关阅读:
    android raw与assets区别
    android 反编译
    sql 随笔
    控件EditText
    android 监听Home键
    android tab之间滑动切换界面功能
    android listview 总结
    SAP云平台上两个ABAP系统实例之间的互连
    什么是SAP OData Model Creator
    Netweaver和Windows,Ubuntu的数据共享
  • 原文地址:https://www.cnblogs.com/520peng/p/8058303.html
Copyright © 2020-2023  润新知