zoukankan      html  css  js  c++  java
  • Java作业十二(2017-11-13)

    /*继承与抽象类*/
    package com.baidu.www;
     	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();
    }
    
    
     	class ZiXia extends Person{
        private float score;
        
        public ZiXia(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;
        }
    }
    
    
     	class ZhiZunBao extends Person {
        private float salary;
        
        public ZhiZunBao(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;
        }
    }
    
    public class GM {
    
        public static void main(String[] args) {
            Person ZiXia=new ZiXia("仙子",19,10);
            Person ZhiZunBao=new ZhiZunBao("人",18, 10);
            print(ZiXia.speak());
            print(ZhiZunBao.speak());
        }
        private static void print(String speak) {
            System.out.println(speak);
        }
    }
    

      

  • 相关阅读:
    uva1220--树的最大独立集+判重
    UVA12186--树型DP
    HDU4171--bfs+树
    远程调用
    高并发业务
    wireshark
    将java程序打包成exe文件
    将博客搬至CSDN
    Mysql分区
    MogileFS
  • 原文地址:https://www.cnblogs.com/chengxuyuanGM/p/7859858.html
Copyright © 2011-2022 走看看