zoukankan      html  css  js  c++  java
  • 2017.12.1T19_B2_4.3kehouzuoye

    package com.whxiong.work04;

    public abstract class Animal {
     private int age;
     public Animal(int age){
      this.age=age;
     }
     public int getAge() {
      return age;
     }
     public void setAge(int age) {
      this.age = age;
     }
     public abstract void info();

    *****************************************

    package com.whxiong.work04;

    public final class Bird extends Animal {
     private String color;

     public Bird(int age, String color) {
      super(age);
      this.color = color;
     }

     public String getColor() {
      return color;
     }

     public void setColor(String color) {
      this.color = color;
     }

     public void info() {
      System.out.println("我是一只" + color + "的鸟! 今年" + this.getAge() + "岁了!");

     *********************************************************

    package com.whxiong.work04;

    public final class Chicken extends Poultry {
     private String type;

     public Chicken(String intrest, String name, String eat, String type) {
      super(intrest, name, eat);
      this.type = type;
     }

     public String getType() {
      return type;
     }

     public void setType(String type) {
      this.type = type;
     }

     public void print() {
      System.out
        .println("我叫" + this.getName() + ",是一只" + this.type + "! 我喜欢吃"
          + this.getEat() + "! 我会" + this.getIntrest() + "!");

     ******************************************

    package com.whxiong.work04;

    public final class Duck extends Poultry {
     private String type;

     public Duck(String intrest, String name, String eat, String type) {
      super(intrest, name, eat);
      this.type = type;
     }

     public String getType() {
      return type;
     }

     public void setType(String type) {
      this.type = type;
     }

     public void print() {
      System.out
        .println("我叫" + this.getName() + ",是一只" + this.type + "! 我喜欢吃"
          + this.getEat() + "! 我会" + this.getIntrest() + "!");
     }

    }************************************************

    package com.whxiong.work04;

    public final class Fish extends Animal {
     private double weight;

     public Fish(int age, double weight) {
      super(age);
      this.weight = weight;
     }

     public double getWeight() {
      return weight;
     }

     public void setWeight(double weight) {
      this.weight = weight;
     }

     public void info() {
      System.out.println("我是一只" + weight + "斤重的鱼! 今年" + this.getAge()
        + "岁了!");

     }*****************************************

    package com.whxiong.work04;

    public abstract class Poultry { // poultry>>>>家禽
     private String intrest;
     private String name;
     private String eat;

     public Poultry(String intrest, String name, String eat) {
      this.intrest = intrest;
      this.name = name;
      this.eat = eat;
     }

     public abstract void print();

     public String getIntrest() {
      return intrest;
     }

     public void setIntrest(String intrest) {
      this.intrest = intrest;
     }

     public String getName() {
      return name;
     }

     public void setName(String name) {
      this.name = name;
     }

     public String getEat() {
      return eat;
     }

     public void setEat(String eat) {
      this.eat = eat;
     }

    **************************************************

    package com.whxiong.work04;

    import java.util.Scanner;

    public class Work04 {

     /**
      * @param args
      */
     public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
      System.out.println("课后习题第五题");
      System.out.println("***********************");
      String color;
      int ageBrid, ageFish;
      double weight;
      System.out.print("请输入鸟的颜色:");
      color = input.next();
      System.out.print("请输入鸟的年龄:");
      ageBrid = input.nextInt();
      System.out.print("请输入鱼的重量:");
      weight = input.nextDouble();
      System.out.print("请输入鱼的鱼龄:");
      ageFish = input.nextInt();
      System.out.println();
      Bird bird = new Bird(ageBrid, color);
      bird.info();
      System.out.println();
      Fish fish = new Fish(ageFish, weight);
      fish.info();

      System.out.println();
      System.out.println("课后习题第六题");
      System.out.println("***********************");
      Chicken chicken = new Chicken("打鸣", "喔喔", "虫子", "芦花鸡");
      chicken.print();
      System.out.println();
      Duck duck = new Duck("游泳", "嘎嘎", "小鱼虾", "斑嘴鸭");
      duck.print();

  • 相关阅读:
    wpf写的httpget请求
    c#的反射机制
    C#中所有的类都继承自哪个类
    使用c#创建windows的桌面的自启服务
    工厂模式的三种实现,就这么简单!
    Github上的沙雕项目,玩100遍都不够
    代理模式的种类、原理及各种实例详解
    面试官问:HashMap在并发情况下为什么造成死循环?一脸懵
    Oracle中 COUNT(count(*))语法
    jquery如何获取当前时间
  • 原文地址:https://www.cnblogs.com/xiaoxiao1016/p/8004823.html
Copyright © 2011-2022 走看看