zoukankan      html  css  js  c++  java
  • 12c 11.13

    package sy;
    
    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 sy;
    
    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 sy;
    
    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 sy;
    
    public class SandW {
    
    
        public static void main(String[] args) {
            Person student=new Student("旺财",23,90.5f);
            Person worker=new Worker("小强",45,18125.5f);
            print(student.speak());
            print(worker.speak());
        }
        private static void print(String speak) {
            System.out.println(speak);
        }
    }
  • 相关阅读:
    UI21-多线程: GCD Grand Center Dispatch
    UI20- CollectionView瀑布流
    UI19-数据库操作:CoreDtata
    UI18-数据库操作:SQL FMDB
    UI17-数据库操作:SQLite
    UI16-通过Xcode将代码提交到github上, 把仓库放在github上
    UI15-存储路径
    UI14-沙盒机制,文件的读写,文件管理器的增删移动复制,归档和反归档。
    UI13-异步下载图片
    数据库相关中间件介绍
  • 原文地址:https://www.cnblogs.com/gaojie77/p/7834557.html
Copyright © 2011-2022 走看看