2022年 一月19号复盘内容二。(继承 多态 接口 抽象(二)

简介: 2022年 一月19号复盘内容二。(继承 多态 接口 抽象(二)

上面的综合案例,让继承的多次使用。

代码如下:

package comExtends.Object;
/**
 * 万物皆对象
 * @author MZFAITHDREAM
 *
 */
public class Object {
  public  String age ;  //年龄
     public  String  sex;//性别
     public String height ;//身高
     public String weight; //体重
     public String color;//色彩
     public String name;
     public String autoplast;//叶绿体
  public String getAge() {
    return age;
  }
  public void setAge(String age) {
    this.age = age;
  }
  public String getSex() {
    return sex;
  }
  public void setSex(String sex) {
    this.sex = sex;
  }
  public String getHeight() {
    return height;
  }
  public void setHeight(String height) {
    this.height = height;
  }
  public String getWeight() {
    return weight;
  }
  public void setWeight(String weight) {
    this.weight = weight;
  }
  public String getColor() {
    return color;
  }
  public void setColor(String color) {
    this.color = color;
  }
  public String getName() {
    return name;
  }
  public void setName(String name) {
    this.name = name;
  }
  public String getAutoplast() {
    return autoplast;
  }
  public void setAutoplast(String autoplast) {
    this.autoplast = autoplast;
  }
  @Override
  public String toString() {
    return "Object [age=" + age + ", sex=" + sex + ", height=" + height + ", weight=" + weight + ", color=" + color
        + ", name=" + name + ", autoplast=" + autoplast + "]";
  }
     //fish people plant Animal
  public void eat() {
    System.out.println("动物要吃饭哦");
  }
  public void sleep() {
    System.out.println("动物要睡觉哦");
  }
  public void run() {
  System.out.println("动物要跑步哦");
     }
  public void lookforagirfriend() {
    System.out.println("动物要找女朋友哦");
  }
  public void sleepfish() {
    System.out.println("鱼要睡觉");
  }
  public void eatfood() {
    System.out.println("鱼要找食物");
  }
  public void swwing() {
       System.out.println("鱼要去游泳哦");
     }
   public void sleepplant()  {
     System.out.println("植物要睡觉");
   }
   public void photosynthesis() {
     System.out.println("植物要光合作用");
   }
   public void eatco2() {
     System.out.println("植物要吸收co2");
   }
    public void peopleeat() {
      System.out.println("人类吃饭要积极");
    }
    public void peoplesleep() {
      System.out.println("睡觉要开心,做个美梦哦");
    }
    public void beat() {
      System.out.println("打嘟嘟  xing xing hubin ");
    }
    public void learn() {
      System.out.println("no pains no gains 学习要积极");
    }
}
package comExtends.Object;
public class ObjectTest {
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    Object object= new Object();
    object.name="object";
    object.age="12";
    object.height="124";
    object.autoplast="cv";
    //方法
    object.beat();
    object.eat();
    object.eatco2();
    object.eatfood();
    object.learn();
    object.lookforagirfriend();
    object.swwing();
    object.sleep();
    object.sleepfish();
    object.sleepplant();
    object.peopleeat();
  }
}

package comExtends.Animal;
public class Animal  extends Object{
    public  String age ;  //年龄
     public  String  sex;//性别
     public String height ;//身高
     public String weight; //体重
     public String color;
  public String name;
     public Animal() {
    // TODO Auto-generated constructor stub
       System.out.println("这是无参构造");
  }
  public Animal(String age, String sex, String height, String weight2, String color) {
    super();
    this.age = age;
    this.sex = sex;
    this.height = height;
    this.weight = weight2;
    this.color = color;
  }
  public String getAge() {
    return age;
  }
  public void setAge(String age) {
    this.age = age;
  }
  public String getSex() {
    return sex;
  }
  public void setSex(String sex) {
    this.sex = sex;
  }
  public void setHeight(String height) {
    this.height = height;
  }
  public String getWeight() {
    return weight;
  }
  public void setWeight(String weight) {
    this.weight = weight;
  }
  public String getColor() {
    return color;
  }
  public void setColor(String color) {
    this.color = color;
  }
  @Override
  public String toString() {
    return "Animal [age=" + age + ", sex=" + sex + ", height=" + height + ", weight=" + weight + ", color=" + color
        + "]";
  }
     //定义方法的构造
  public void eat() {
    System.out.println("动物要吃饭哦");
  }
  public void sleep() {
    System.out.println("动物要睡觉哦");
  }
  public void run() {
  System.out.println("动物要跑步哦");
     }
  public void lookforagirfriend() {
    System.out.println("动物要找女朋友哦");
  }
  public void setWeight(int weight) {
    // TODO Auto-generated method stub
  }
}
package comExtends.Animal;
public class cat  extends Animal{
  public cat() {
    // TODO Auto-generated constructor stub
  }
  public cat(String age, String sex, String height, int weight, String color) {
    super();
    // TODO Auto-generated constructor stub
  }
  @Override
  public String getAge() {
    // TODO Auto-generated method stub
    return super.getAge();
  }
  @Override
  public void setAge(String age) {
    // TODO Auto-generated method stub
    super.setAge(age);
  }
  @Override
  public String getSex() {
    // TODO Auto-generated method stub
    return super.getSex();
  }
  @Override
  public void setSex(String sex) {
    // TODO Auto-generated method stub
    super.setSex(sex);
  }
  @Override
  public void setHeight(String height) {
    // TODO Auto-generated method stub
    super.setHeight(height);
  }
  @Override
  public String getColor() {
    // TODO Auto-generated method stub
    return super.getColor();
  }
  @Override
  public void setColor(String color) {
    // TODO Auto-generated method stub
    super.setColor(color);
  }
  @Override
  public String toString() {
    // TODO Auto-generated method stub
    return super.toString();
  }
  @Override
  public void eat() {
    // TODO Auto-generated method stub
    System.out.println("pig吃饭");
    super.eat();
  }
  @Override
  public void sleep() {
    // TODO Auto-generated method stub
    System.out.println("pig在睡觉");
    super.sleep();
  }
  @Override
  public void run() {
    // TODO Auto-generated method stub
    System.out.println("pig在跑步");
    super.run();
  }
  @Override
  public void lookforagirfriend() {
    // TODO Auto-generated method stub
    System.out.println("pig在找女朋友");
    super.lookforagirfriend();
  }
}

package comExtends.Animal;
public class Dog  extends Animal{
  public Dog() {
    // TODO Auto-generated constructor stub
  }
  public Dog(String age, String sex, String height, int weight, String color) {
    super();
    // TODO Auto-generated constructor stub
  }
  @Override
  public String getAge() {
    // TODO Auto-generated method stub
    return super.getAge();
  }
  @Override
  public void setAge(String age) {
    // TODO Auto-generated method stub
    super.setAge(age);
  }
  @Override
  public String getSex() {
    // TODO Auto-generated method stub
    return super.getSex();
  }
  @Override
  public void setSex(String sex) {
    // TODO Auto-generated method stub
    super.setSex(sex);
  }
  @Override
  public void setHeight(String height) {
    // TODO Auto-generated method stub
    super.setHeight(height);
  }
  @Override
  public String getWeight() {
    // TODO Auto-generated method stub
    return super.getWeight();
  }
  @Override
  public String getColor() {
    // TODO Auto-generated method stub
    return super.getColor();
  }
  @Override
  public void setColor(String color) {
    // TODO Auto-generated method stub
    super.setColor(color);
  }
  @Override
  public String toString() {
    // TODO Auto-generated method stub
    return super.toString();
  }
  @Override
  public void eat() {
    // TODO Auto-generated method stub
    System.out.println("Dog吃饭");
    super.eat();
  }
  @Override
  public void sleep() {
    // TODO Auto-generated method stub
    System.out.println("Dog在睡觉");
    super.sleep();
  }
  @Override
  public void run() {
    // TODO Auto-generated method stub
    System.out.println("在跑步");
    super.run();
  }
  @Override
  public void lookforagirfriend() {
    // TODO Auto-generated method stub
    System.out.println("Dog 要交女朋友");
    super.lookforagirfriend();
  }
}

package comExtends.Animal;
public class pig  extends Animal{
  public pig() {
    // TODO Auto-generated constructor stub
  }
  public pig(String age, String sex, String height, int weight, String color) {
    super();
    // TODO Auto-generated constructor stub
  }
  @Override
  public String getAge() {
    // TODO Auto-generated method stub
    return super.getAge();
  }
  @Override
  public void setAge(String age) {
    // TODO Auto-generated method stub
    super.setAge(age);
  }
  @Override
  public String getSex() {
    // TODO Auto-generated method stub
    return super.getSex();
  }
  @Override
  public void setSex(String sex) {
    // TODO Auto-generated method stub
    super.setSex(sex);
  }
  @Override
  public void setHeight(String height) {
    // TODO Auto-generated method stub
    super.setHeight(height);
  }
  @Override
  public void setWeight(int weight) {
    // TODO Auto-generated method stub
    super.setWeight(weight);
  }
  @Override
  public String getColor() {
    // TODO Auto-generated method stub
    return super.getColor();
  }
  @Override
  public void setColor(String color) {
    // TODO Auto-generated method stub
    super.setColor(color);
  }
  @Override
  public String toString() {
    // TODO Auto-generated method stub
    return super.toString();
  }
  @Override
  public void eat() {
    // TODO Auto-generated method stub
    System.out.println("pig吃饭");
    super.eat();
  }
  @Override
  public void sleep() {
    // TODO Auto-generated method stub
    System.out.println("pig在睡觉");
    super.sleep();
  }
  @Override
  public void run() {
    // TODO Auto-generated method stub
    System.out.println("pig在跑步");
    super.run();
  }
  @Override
  public void lookforagirfriend() {
    // TODO Auto-generated method stub
    System.out.println("pig在找女朋友");
    super.lookforagirfriend();
  }
}

package comExtends.Fish;
public class Fish {
  public  String age ;  //年龄
     public  String  sex;//性别
     public String height ;//身高
     public String weight; //体重
     public String name;
     public String color;
     public Fish() {
    // TODO Auto-generated constructor stub
       System.out.println("鱼的无惨构造");
  }
  public Fish(String age, String sex, String height, String weight, String name, String color) {
    super();
    this.age = age;
    this.sex = sex;
    this.height = height;
    this.weight = weight;
    this.name = name;
    this.color = color;
  }
  public String getAge() {
    return age;
  }
  public void setAge(String age) {
    this.age = age;
  }
  public String getSex() {
    return sex;
  }
  public void setSex(String sex) {
    this.sex = sex;
  }
  public void setHeight(String height) {
    this.height = height;
  }
  public String getWeight() {
    return weight;
  }
  public void setWeight(String weight) {
    this.weight = weight;
  }
  public String getName() {
    return name;
  }
  public void setName(String name) {
    this.name = name;
  }
  public String getColor() {
    return color;
  }
  public void setColor(String color) {
    this.color = color;
  }
  @Override
  public String toString() {
    return "Fish [age=" + age + ", sex=" + sex + ", height=" + height + ", weight=" + weight + ", name=" + name
        + ", color=" + color + "]";
  }
     //定义鱼的方法动作行为
  public void sleepfish() {
    System.out.println("鱼要睡觉");
  }
  public void eatfood() {
    System.out.println("鱼要找食物");
  }
  public void swwing() {
       System.out.println("鱼要去游泳哦");
     }
  public void setAge(int age) {
    // TODO Auto-generated method stub
  }
  public void setWeight(int weight) {
    // TODO Auto-generated method stub
  }
}

package comExtends.Fish;
public class carp extends Fish{
  public carp() {
    // TODO Auto-generated constructor stub
  }
  public carp(int age, String sex, int height, int weight, String name, String color) {
    super();
    // TODO Auto-generated constructor stub
  }
  @Override
  public String getAge() {
    // TODO Auto-generated method stub
    return super.getAge();
  }
  @Override
  public String getSex() {
    // TODO Auto-generated method stub
    return super.getSex();
  }
  @Override
  public void setSex(String sex) {
    // TODO Auto-generated method stub
    super.setSex(sex);
  }
  @Override
  public String getName() {
    // TODO Auto-generated method stub
    return super.getName();
  }
  @Override
  public void setName(String name) {
    // TODO Auto-generated method stub
    super.setName(name);
  }
  @Override
  public String getColor() {
    // TODO Auto-generated method stub
    return super.getColor();
  }
  @Override
  public void setColor(String color) {
    // TODO Auto-generated method stub
    System.out.println("鱼的色彩为红色");
  }
  @Override
  public void sleepfish() {
    // TODO Auto-generated method stub
    System.out.println("鱼在水里游泳");
  }
  @Override
  public void eatfood() {
    // TODO Auto-generated method stub
    System.out.println("鱼在找食物");
  }
  @Override
  public void swwing() {
    // TODO Auto-generated method stub
    System.out.println("鱼在游泳");
  }
}

package comExtends.Fish;
/**
 * 青鱼
 * @author MZFAITHDREAM
 *
 */
public class herring extends Fish{
  public herring() {
    // TODO Auto-generated constructor stub
  }
  public herring(int age, String sex, int height, int weight, String name, String color) {
    super();
    // TODO Auto-generated constructor stub
  }
  @Override
  public String getAge() {
    // TODO Auto-generated method stub
    return super.getAge();
  }
  @Override
  public void setAge(int age) {
    // TODO Auto-generated method stub
    super.setAge(age);
  }
  @Override
  public String getSex() {
    // TODO Auto-generated method stub
    return super.getSex();
  }
  @Override
  public void setSex(String sex) {
    // TODO Auto-generated method stub
    super.setSex(sex);
  }
  @Override
  public String getName() {
    // TODO Auto-generated method stub
    return super.getName();
  }
  @Override
  public void setName(String name) {
    // TODO Auto-generated method stub
    super.setName(name);
  }
  @Override
  public String getColor() {
    // TODO Auto-generated method stub
    return super.getColor();
  }
  @Override
  public void setColor(String color) {
    // TODO Auto-generated method stub
    super.setColor(color);
  }
  @Override
  public String toString() {
    // TODO Auto-generated method stub
    return super.toString();
  }
  @Override
  public void sleepfish() {
    // TODO Auto-generated method stub\
    System.out.println("herringeatsleep");
    super.sleepfish();
  }
  @Override
  public void eatfood() {
    // TODO Auto-generated method stub
    System.out.println("herring在eatfood");
    super.eatfood();
  }
  @Override
  public void swwing() {
    System.out.println("herring在游泳");
    super.swwing();
  }
  public void w() {
    System.out.println("这是herring的特殊行为");
  }
}

package comExtends.Fish;
/**
 * 青鱼
 * @author MZFAITHDREAM
 *
 */
public class herring extends Fish{
  public herring() {
    // TODO Auto-generated constructor stub
  }
  public herring(int age, String sex, int height, int weight, String name, String color) {
    super();
    // TODO Auto-generated constructor stub
  }
  @Override
  public String getAge() {
    // TODO Auto-generated method stub
    return super.getAge();
  }
  @Override
  public void setAge(int age) {
    // TODO Auto-generated method stub
    super.setAge(age);
  }
  @Override
  public String getSex() {
    // TODO Auto-generated method stub
    return super.getSex();
  }
  @Override
  public void setSex(String sex) {
    // TODO Auto-generated method stub
    super.setSex(sex);
  }
  @Override
  public String getName() {
    // TODO Auto-generated method stub
    return super.getName();
  }
  @Override
  public void setName(String name) {
    // TODO Auto-generated method stub
    super.setName(name);
  }
  @Override
  public String getColor() {
    // TODO Auto-generated method stub
    return super.getColor();
  }
  @Override
  public void setColor(String color) {
    // TODO Auto-generated method stub
    super.setColor(color);
  }
  @Override
  public String toString() {
    // TODO Auto-generated method stub
    return super.toString();
  }
  @Override
  public void sleepfish() {
    // TODO Auto-generated method stub\
    System.out.println("herringeatsleep");
    super.sleepfish();
  }
  @Override
  public void eatfood() {
    // TODO Auto-generated method stub
    System.out.println("herring在eatfood");
    super.eatfood();
  }
  @Override
  public void swwing() {
    System.out.println("herring在游泳");
    super.swwing();
  }
  public void w() {
    System.out.println("这是herring的特殊行为");
  }
}

package comExtends.Fish;
public class FishTest {
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    Fish a= new carp();
    a.eatfood();
    a.hashCode();
    a.sleepfish();
    a.swwing();
    System.out.println("--------对象一");
    Fish b= new crucian();
    b.eatfood();
    b.hashCode();
    b.sleepfish();
    b.swwing();
    System.out.println("------------对象二");
    Fish c= new herring();
    System.out.println("===================");
    c.age="13";
    c.color="black";
    c.name="herring";
    c.sex="女";
    c.weight="12";
    System.out.println(c.age+
        c.color+
        c.height+
        c.name+
        c.weight+
        c.weight);
    c.eatfood();
    c.hashCode();
    c.sleepfish();
    c.swwing();
  }
}
package comExtends.People;
import comExtends.Object.Object;
public class doctor extends Object {
  public doctor() {
    super();
    // TODO Auto-generated constructor stub
  }
  public doctor(int age, String sex, int height, int weight, String color, String name, String autoplast) {
    super();
    // TODO Auto-generated constructor stub
  }
  @Override
  public void eat() {
    // TODO Auto-generated method stub
    super.eat();
  }
  @Override
  public void sleep() {
    // TODO Auto-generated method stub
    System.out.println("医生在睡觉");
  }
  @Override
  public void run() {
    // TODO Auto-generated method stub
      System.out.println("医生在跑步");
  }
  @Override
  public void swwing() {
    // TODO Auto-generated method stub
    System.out.println("医生在游泳");
  }
  @Override
  public void beat() {
    // TODO Auto-generated method stub
    System.out.println("医生在打豆豆");
  }
  public void savepeople() {
    System.out.println("医生savepeople");
  }
}

package comExtends.People;
public class PeopleTest {
  public static void main(String[] args) {
    //1
    People p =new People();
    System.out.println("继承用extends修饰,指的是x属于y的一种");
    System.out.println("继承是is...........a的关系");
    System.out.println("student and teacher or solder是 people的一种");
    System.out.println(p);
    p.name ="小王";
    p.height =148;
    p.weight =67;
    p.age=89;
    p.sex="nv";
    System.out.println(p.name);
    System.out.println(p.height+"cm");
    System.out.println(p.weight+"kg");
    System.out.println(p.age+"nain");
    System.out.println(p.sex);
    p.beat();
    p.peoplesleep();
    p.peopleeat();
    p.learn();
    System.out.println("==================对象一===========================");
    //2
    Student s =new Student();
    System.out.println(s);
    s.age=20;
    s.name="限胡";
    s.height =178;
    s.weight =67;
    s.age=89;
    s.sex="nan";
    System.out.println(s.name);
    System.out.println(s.height+"cm");
    System.out.println(s.weight+"kg");
    System.out.println(s.age+"nain");
    System.out.println(s.sex);
    s.peopleeat();
    s.beat();
    s.learn();
    s.dohomework();
    System.out.println("==================对象二===============================");
    //3
    Teacher  t =new Teacher();
    System.out.println(t);
    t.name="户外";
    t.age=34;
    t.height=167;
    t.weight=64;
    t.sex="nan";
    //成员变量
    System.out.println(t.name);
    System.out.println(t.height+"cm");
    System.out.println(t.weight+"kg");
    System.out.println(t.age+"nain");
    System.out.println(t.sex);
    //成员方法
    t.learnchinese();
    t.learnenglish();
    t.learnmath();
    t.beat();
    t.learn();
    System.out.println("==================对象三==================");
    Solder d =new Solder ();
    d.name="户外yu";
    d.age=34;
    d.height=167;
    d.weight=64;
    d.sex="nan";
    System.out.println(d.name);
    System.out.println(d.height+"cm");
    System.out.println(d.weight+"kg");
    System.out.println(d.age+"nain");
    System.out.println(d.sex);
    //成员方法
    d.playgrams();
    d.learn();
    d.run();
    d.tranning();
    d.beat();
    d.learn();
    System.out.println("-----------------对象四");
    People  e =new sportsman ();
    e.beat();
    e.learn();
  }
}

package comExtends.People;
public class PeopleTest {
  public static void main(String[] args) {
    //1
    People p =new People();
    System.out.println("继承用extends修饰,指的是x属于y的一种");
    System.out.println("继承是is...........a的关系");
    System.out.println("student and teacher or solder是 people的一种");
    System.out.println(p);
    p.name ="小王";
    p.height =148;
    p.weight =67;
    p.age=89;
    p.sex="nv";
    System.out.println(p.name);
    System.out.println(p.height+"cm");
    System.out.println(p.weight+"kg");
    System.out.println(p.age+"nain");
    System.out.println(p.sex);
    p.beat();
    p.peoplesleep();
    p.peopleeat();
    p.learn();
    System.out.println("==================对象一===========================");
    //2
    Student s =new Student();
    System.out.println(s);
    s.age=20;
    s.name="限胡";
    s.height =178;
    s.weight =67;
    s.age=89;
    s.sex="nan";
    System.out.println(s.name);
    System.out.println(s.height+"cm");
    System.out.println(s.weight+"kg");
    System.out.println(s.age+"nain");
    System.out.println(s.sex);
    s.peopleeat();
    s.beat();
    s.learn();
    s.dohomework();
    System.out.println("==================对象二===============================");
    //3
    Teacher  t =new Teacher();
    System.out.println(t);
    t.name="户外";
    t.age=34;
    t.height=167;
    t.weight=64;
    t.sex="nan";
    //成员变量
    System.out.println(t.name);
    System.out.println(t.height+"cm");
    System.out.println(t.weight+"kg");
    System.out.println(t.age+"nain");
    System.out.println(t.sex);
    //成员方法
    t.learnchinese();
    t.learnenglish();
    t.learnmath();
    t.beat();
    t.learn();
    System.out.println("==================对象三==================");
    Solder d =new Solder ();
    d.name="户外yu";
    d.age=34;
    d.height=167;
    d.weight=64;
    d.sex="nan";
    System.out.println(d.name);
    System.out.println(d.height+"cm");
    System.out.println(d.weight+"kg");
    System.out.println(d.age+"nain");
    System.out.println(d.sex);
    //成员方法
    d.playgrams();
    d.learn();
    d.run();
    d.tranning();
    d.beat();
    d.learn();
    System.out.println("-----------------对象四");
    People  e =new sportsman ();
    e.beat();
    e.learn();
  }
}

package comExtends.People;
public class sportsman extends People{
  public sportsman() {
    // TODO Auto-generated constructor stub
    System.out.println("运动员");
  }
  public sportsman(int age, String sex, int height, int weight, String name) {
    super(age, sex, height, weight, name);
    // TODO Auto-generated constructor stub
  }
  @Override
  public void setAge(int age) {
    // TODO Auto-generated method stub
    super.setAge(age);
  }
  @Override
  public String getSex() {
    // TODO Auto-generated method stub
    return super.getSex();
  }
  @Override
  public void setSex(String sex) {
    // TODO Auto-generated method stub
    super.setSex(sex);
  }
  @Override
  public void setHeight(int height) {
    // TODO Auto-generated method stub
    super.setHeight(height);
  }
  @Override
  public void setWeight(int weight) {
    // TODO Auto-generated method stub
    super.setWeight(weight);
  }
  @Override
  public String getName() {
    // TODO Auto-generated method stub
    return super.getName();
  }
  @Override
  public void setName(String name) {
    // TODO Auto-generated method stub
    super.setName(name);
  }
  @Override
  public void peopleeat() {
    // TODO Auto-generated method stub
    super.peopleeat();
  }
  @Override
  public void peoplesleep() {
    // TODO Auto-generated method stub
    super.peoplesleep();
  }
  @Override
  public void beat() {
    // TODO Auto-generated method stub
    super.beat();
  }
  @Override
  public void learn() {
    // TODO Auto-generated method stub
    System.out.println("sportsman在学习");
    super.learn();
  }
}

package comExtends.People;
public class Student  extends People{
   public  int age ;  //年龄
     public  String  sex;//性别
     public int height ;//身高
     public int weight; //体重
     public String name;
  public Student() {
    super();
    // TODO Auto-generated constructor stub
  }
  public Student(int age, String sex, int height, int weight, String name) {
    super(age, sex, height, weight, name);
    // TODO Auto-generated constructor stub
  }
     public void dohomework() {
       System.out.println("学生写字");
     }
}

package comExtends.People;
public class Teacher extends People{
     public  int age ;  //年龄
     public  String  sex;//性别
     public int height ;//身高
     public int weight; //体重
     public String name;
  public Teacher() {
    super();
  }
  public Teacher(int age, String sex, int height, int weight, String name) {
    super(age, sex, height, weight, name);
    // TODO Auto-generated constructor stub
  }
  public void learnenglish() {
    System.out.println("can not obery himself is to other");
  }
  public void learnmath() {
    System.out.println("math 学习数学强思路");
  }
     public void learnchinese() {
       System.out.println("学习语文提高文化素质");
  }
}

package comExtends.Plant;
public class lilu  extends Plant{
  public lilu() {
    // TODO Auto-generated constructor stub
  }
  public lilu(int age, int height, int weight, String name, String color, String autoplast) {
    super(age, height, weight, name, color, autoplast);
    // TODO Auto-generated constructor stub
  }
  @Override
  public void setAge(int age) {
    // TODO Auto-generated method stub
    super.setAge(age);
  }
  @Override
  public void setHeight(int height) {
    // TODO Auto-generated method stub
    super.setHeight(height);
  }
  @Override
  public int getWeight() {
    // TODO Auto-generated method stub
    return super.getWeight();
  }
  @Override
  public void setWeight(int weight) {
    // TODO Auto-generated method stub
    super.setWeight(weight);
  }
  @Override
  public String getName() {
    // TODO Auto-generated method stub
    return super.getName();
  }
  @Override
  public void setName(String name) {
    // TODO Auto-generated method stub
    super.setName(name);
  }
  @Override
  public String getColor() {
    // TODO Auto-generated method stub
    return super.getColor();
  }
  @Override
  public void setColor(String color) {
    // TODO Auto-generated method stub
    super.setColor(color);
  }
  @Override
  public String getAutoplast() {
    // TODO Auto-generated method stub
    return super.getAutoplast();
  }
  @Override
  public void setAutoplast(String autoplast) {
    // TODO Auto-generated method stub
    super.setAutoplast(autoplast);
  }
  @Override
  public String toString() {
    // TODO Auto-generated method stub
    return super.toString();
  }
  @Override
  public void sleepplant() {
    // TODO Auto-generated method stub
    System.out.println("lilu在睡觉");
    super.sleepplant();
  }
  @Override
  public void photosynthesis() {
    // TODO Auto-generated method stub
    System.out.println("lilu在光合作用");
    super.photosynthesis();
  }
  @Override
  public void eatco2() {
    // TODO Auto-generated method stub
    System.out.println("lilu在收co2");
    super.eatco2();
  }
}
package comExtends.Plant;
public class Plant extends Object {
  //定义植物
  public  int age ;  //年龄
     public int height ;//身高
     public int weight; //体重
     public String name;
     public String color;
     public String autoplast;//叶绿体
     public Plant() {
    // TODO Auto-generated constructor stub
       System.out.println("植物的无惨构造");
  }
  public Plant(int age, int height, int weight, String name, String color, String autoplast) {
    super();
    this.age = age;
    this.height = height;
    this.weight = weight;
    this.name = name;
    this.color = color;
    this.autoplast = autoplast;
  }
  public void setAge(int age) {
    this.age = age;
  }
  public void setHeight(int height) {
    this.height = height;
  }
  public int getWeight() {
    return weight;
  }
  public void setWeight(int weight) {
    this.weight = weight;
  }
  public String getName() {
    return name;
  }
  public void setName(String name) {
    this.name = name;
  }
  public String getColor() {
    return color;
  }
  public void setColor(String color) {
    this.color = color;
  }
  public String getAutoplast() {
    return autoplast;
  }
  public void setAutoplast(String autoplast) {
    this.autoplast = autoplast;
  }
   public void sleepplant()  {
     System.out.println("植物要睡觉");
   }
   public void photosynthesis() {
     System.out.println("植物要光合作用");
   }
   public void eatco2() {
     System.out.println("植物要吸收co2");
   }
}
package comExtends.Plant;
public class rose  extends Plant{
  public rose() {
    // TODO Auto-generated constructor stub
  }
  public rose(int age, int height, int weight, String name, String color, String autoplast) {
    super(age, height, weight, name, color, autoplast);
    // TODO Auto-generated constructor stub
  }
  @Override
  public void setAge(int age) {
    // TODO Auto-generated method stub
    super.setAge(age);
  }
  @Override
  public void setHeight(int height) {
    // TODO Auto-generated method stub
    super.setHeight(height);
  }
  @Override
  public int getWeight() {
    // TODO Auto-generated method stub
    return super.getWeight();
  }
  @Override
  public void setWeight(int weight) {
    // TODO Auto-generated method stub
    super.setWeight(weight);
  }
  @Override
  public String getName() {
    // TODO Auto-generated method stub
    return super.getName();
  }
  @Override
  public void setName(String name) {
    // TODO Auto-generated method stub
    super.setName(name);
  }
  @Override
  public String getColor() {
    // TODO Auto-generated method stub
    return super.getColor();
  }
  @Override
  public void setColor(String color) {
    // TODO Auto-generated method stub
    super.setColor(color);
  }
  @Override
  public String getAutoplast() {
    // TODO Auto-generated method stub
    return super.getAutoplast();
  }
  @Override
  public void setAutoplast(String autoplast) {
    // TODO Auto-generated method stub
    super.setAutoplast(autoplast);
  }
  @Override
  public String toString() {
    // TODO Auto-generated method stub
    return super.toString();
  }
  @Override
  public void sleepplant() {
    // TODO Auto-generated method stub
    System.out.println("rose 在晚上睡觉");
  }
  @Override
  public void photosynthesis() {
    // TODO Auto-generated method stub
    System.out.println("rose 在叶绿体中光合作用");
    super.photosynthesis();
  }
  @Override
  public void eatco2() {
    // TODO Auto-generated method stub
    System.out.println("rose 在收co2");
    super.eatco2();
  }
}
package comExtends.Plant;
public class tulip  extends Plant{
  public tulip() {
    // TODO Auto-generated constructor stub
  }
  @Override
  public void setAge(int age) {
    // TODO Auto-generated method stub
    super.setAge(age);
  }
  @Override
  public void setHeight(int height) {
    // TODO Auto-generated method stub
    super.setHeight(height);
  }
  @Override
  public int getWeight() {
    // TODO Auto-generated method stub
    return super.getWeight();
  }
  @Override
  public void setWeight(int weight) {
    // TODO Auto-generated method stub
    super.setWeight(weight);
  }
  @Override
  public String getName() {
    // TODO Auto-generated method stub
    return super.getName();
  }
  @Override
  public void setName(String name) {
    // TODO Auto-generated method stub
    super.setName(name);
  }
  @Override
  public String getColor() {
    // TODO Auto-generated method stub
    return super.getColor();
  }
  @Override
  public void setColor(String color) {
    // TODO Auto-generated method stub
    super.setColor(color);
  }
  @Override
  public String getAutoplast() {
    // TODO Auto-generated method stub
    return super.getAutoplast();
  }
  @Override
  public void setAutoplast(String autoplast) {
    // TODO Auto-generated method stub
    super.setAutoplast(autoplast);
  }
  @Override
  public String toString() {
    // TODO Auto-generated method stub
    return super.toString();
  }
  @Override
  public void sleepplant() {
    // TODO Auto-generated method stub
    System.out.println("在tulip睡觉");
    super.sleepplant();
  }
  @Override
  public void photosynthesis() {
    // TODO Auto-generated method stub
    super.photosynthesis();
  }
  @Override
  public void eatco2() {
    // TODO Auto-generated method stub
    System.out.println("tulip eat Co2");
    super.eatco2();
  }
  public void  tulipcolor() {
    System.out.println("tulip色彩yellow");
  }
}

package comExtends.Plant;
public class lilu  extends Plant{
  public lilu() {
    // TODO Auto-generated constructor stub
  }
  public lilu(int age, int height, int weight, String name, String color, String autoplast) {
    super(age, height, weight, name, color, autoplast);
    // TODO Auto-generated constructor stub
  }
  @Override
  public void setAge(int age) {
    // TODO Auto-generated method stub
    super.setAge(age);
  }
  @Override
  public void setHeight(int height) {
    // TODO Auto-generated method stub
    super.setHeight(height);
  }
  @Override
  public int getWeight() {
    // TODO Auto-generated method stub
    return super.getWeight();
  }
  @Override
  public void setWeight(int weight) {
    // TODO Auto-generated method stub
    super.setWeight(weight);
  }
  @Override
  public String getName() {
    // TODO Auto-generated method stub
    return super.getName();
  }
  @Override
  public void setName(String name) {
    // TODO Auto-generated method stub
    super.setName(name);
  }
  @Override
  public String getColor() {
    // TODO Auto-generated method stub
    return super.getColor();
  }
  @Override
  public void setColor(String color) {
    // TODO Auto-generated method stub
    super.setColor(color);
  }
  @Override
  public String getAutoplast() {
    // TODO Auto-generated method stub
    return super.getAutoplast();
  }
  @Override
  public void setAutoplast(String autoplast) {
    // TODO Auto-generated method stub
    super.setAutoplast(autoplast);
  }
  @Override
  public String toString() {
    // TODO Auto-generated method stub
    return super.toString();
  }
  @Override
  public void sleepplant() {
    // TODO Auto-generated method stub
    System.out.println("lilu在睡觉");
    super.sleepplant();
  }
  @Override
  public void photosynthesis() {
    // TODO Auto-generated method stub
    System.out.println("lilu在光合作用");
    super.photosynthesis();
  }
  @Override
  public void eatco2() {
    // TODO Auto-generated method stub
    System.out.println("lilu在收co2");
    super.eatco2();
  }
}
package comExtends.Plant;
public class Plant extends Object {
  //定义植物
  public  int age ;  //年龄
     public int height ;//身高
     public int weight; //体重
     public String name;
     public String color;
     public String autoplast;//叶绿体
     public Plant() {
    // TODO Auto-generated constructor stub
       System.out.println("植物的无惨构造");
  }
  public Plant(int age, int height, int weight, String name, String color, String autoplast) {
    super();
    this.age = age;
    this.height = height;
    this.weight = weight;
    this.name = name;
    this.color = color;
    this.autoplast = autoplast;
  }
  public void setAge(int age) {
    this.age = age;
  }
  public void setHeight(int height) {
    this.height = height;
  }
  public int getWeight() {
    return weight;
  }
  public void setWeight(int weight) {
    this.weight = weight;
  }
  public String getName() {
    return name;
  }
  public void setName(String name) {
    this.name = name;
  }
  public String getColor() {
    return color;
  }
  public void setColor(String color) {
    this.color = color;
  }
  public String getAutoplast() {
    return autoplast;
  }
  public void setAutoplast(String autoplast) {
    this.autoplast = autoplast;
  }
   public void sleepplant()  {
     System.out.println("植物要睡觉");
   }
   public void photosynthesis() {
     System.out.println("植物要光合作用");
   }
   public void eatco2() {
     System.out.println("植物要吸收co2");
   }
}
package comExtends.Plant;
public class rose  extends Plant{
  public rose() {
    // TODO Auto-generated constructor stub
  }
  public rose(int age, int height, int weight, String name, String color, String autoplast) {
    super(age, height, weight, name, color, autoplast);
    // TODO Auto-generated constructor stub
  }
  @Override
  public void setAge(int age) {
    // TODO Auto-generated method stub
    super.setAge(age);
  }
  @Override
  public void setHeight(int height) {
    // TODO Auto-generated method stub
    super.setHeight(height);
  }
  @Override
  public int getWeight() {
    // TODO Auto-generated method stub
    return super.getWeight();
  }
  @Override
  public void setWeight(int weight) {
    // TODO Auto-generated method stub
    super.setWeight(weight);
  }
  @Override
  public String getName() {
    // TODO Auto-generated method stub
    return super.getName();
  }
  @Override
  public void setName(String name) {
    // TODO Auto-generated method stub
    super.setName(name);
  }
  @Override
  public String getColor() {
    // TODO Auto-generated method stub
    return super.getColor();
  }
  @Override
  public void setColor(String color) {
    // TODO Auto-generated method stub
    super.setColor(color);
  }
  @Override
  public String getAutoplast() {
    // TODO Auto-generated method stub
    return super.getAutoplast();
  }
  @Override
  public void setAutoplast(String autoplast) {
    // TODO Auto-generated method stub
    super.setAutoplast(autoplast);
  }
  @Override
  public String toString() {
    // TODO Auto-generated method stub
    return super.toString();
  }
  @Override
  public void sleepplant() {
    // TODO Auto-generated method stub
    System.out.println("rose 在晚上睡觉");
  }
  @Override
  public void photosynthesis() {
    // TODO Auto-generated method stub
    System.out.println("rose 在叶绿体中光合作用");
    super.photosynthesis();
  }
  @Override
  public void eatco2() {
    // TODO Auto-generated method stub
    System.out.println("rose 在收co2");
    super.eatco2();
  }
}
package comExtends.Plant;
public class tulip  extends Plant{
  public tulip() {
    // TODO Auto-generated constructor stub
  }
  @Override
  public void setAge(int age) {
    // TODO Auto-generated method stub
    super.setAge(age);
  }
  @Override
  public void setHeight(int height) {
    // TODO Auto-generated method stub
    super.setHeight(height);
  }
  @Override
  public int getWeight() {
    // TODO Auto-generated method stub
    return super.getWeight();
  }
  @Override
  public void setWeight(int weight) {
    // TODO Auto-generated method stub
    super.setWeight(weight);
  }
  @Override
  public String getName() {
    // TODO Auto-generated method stub
    return super.getName();
  }
  @Override
  public void setName(String name) {
    // TODO Auto-generated method stub
    super.setName(name);
  }
  @Override
  public String getColor() {
    // TODO Auto-generated method stub
    return super.getColor();
  }
  @Override
  public void setColor(String color) {
    // TODO Auto-generated method stub
    super.setColor(color);
  }
  @Override
  public String getAutoplast() {
    // TODO Auto-generated method stub
    return super.getAutoplast();
  }
  @Override
  public void setAutoplast(String autoplast) {
    // TODO Auto-generated method stub
    super.setAutoplast(autoplast);
  }
  @Override
  public String toString() {
    // TODO Auto-generated method stub
    return super.toString();
  }
  @Override
  public void sleepplant() {
    // TODO Auto-generated method stub
    System.out.println("在tulip睡觉");
    super.sleepplant();
  }
  @Override
  public void photosynthesis() {
    // TODO Auto-generated method stub
    super.photosynthesis();
  }
  @Override
  public void eatco2() {
    // TODO Auto-generated method stub
    System.out.println("tulip eat Co2");
    super.eatco2();
  }
  public void  tulipcolor() {
    System.out.println("tulip色彩yellow");
  }
}

相关文章
|
2月前
|
Java 程序员 C++
抽象类 vs 接口:如何在实际项目中做出正确选择?
小米讲解了Java中的抽象类和接口,分析了两者的异同及使用场景。抽象类适合共享状态和行为逻辑,接口适用于提供统一行为规范,尤其在多继承场景下。文中通过实例说明了如何选择使用抽象类或接口,帮助开发者更好地理解这两者在实际开发中的应用。
28 0
|
6月前
详尽分享继承和多态对应的几类问题
详尽分享继承和多态对应的几类问题
28 0
2022年 一月19号复盘内容二。(继承 多态 接口 抽象(三)
2022年 一月19号复盘内容二。(继承 多态 接口 抽象(三)
46 0
2022年 一月19号复盘内容二。(继承 多态 接口 抽象)(一)
2022年 一月19号复盘内容二。(继承 多态 接口 抽象)(一)
49 0
|
Java
2022年/一月18号善于复盘回顾内容一(java的面向对象编程中的类对象属性 方法)Java面向对象的核心继承 封装 多态。(一)
2022年/一月18号善于复盘回顾内容一(java的面向对象编程中的类对象属性 方法)Java面向对象的核心继承 封装 多态。
95 0
2022年/一月18号善于复盘回顾内容一(java的面向对象编程中的类对象属性 方法)Java面向对象的核心继承 封装 多态。(一)
|
Java
2022年/一月18号善于复盘回顾内容一(java的面向对象编程中的类对象属性 方法)Java面向对象的核心继承 封装 多态。(二)
2022年/一月18号善于复盘回顾内容一(java的面向对象编程中的类对象属性 方法)Java面向对象的核心继承 封装 多态。
89 0
2022年/一月18号善于复盘回顾内容一(java的面向对象编程中的类对象属性 方法)Java面向对象的核心继承 封装 多态。(二)
|
C# 索引
【C#】【平时作业】习题-7-继承、抽象与多态
【C#】【平时作业】习题-7-继承、抽象与多态
148 0
【C#】【平时作业】习题-7-继承、抽象与多态
系统认知Java接口、接口与继承、接口与多态
在面向对象的基础之上,接口的出现是类性质的一种完善,是继承机制的一种补充,是体现多态性的一种形式。从生活实际出发,接口把它之下一系列复杂的逻辑,功能等通过“实现接口”的方式封装简化出来,只通过连接一个小小的口子就轻而易举地实现了背后实则很复杂的功能。我想这就是接口存在的意义所在吧。
222 0
系统认知Java接口、接口与继承、接口与多态
|
Java 数据库 数据安全/隐私保护
规则之间-方法覆写限制 | 带你学《Java面向对象编程》之四十
本节向读者介绍了覆写方法过程中的一些限制,并拓宽读者对访问权限控制符的认识,帮助读者进行有效的方法覆写。
|
开发者
适配器类(便利类)的由来:当你自己写的类中想用某个接口中个别方法的时候(注意:不是所有的方法),肿么办?
有的时候需要将接口和抽象类配合起来使用,这样可以为开发者提供相当的便利性,开发者觉得哪个方便就选用哪个。这样的抽象类称为便利类。此时,便利类并不需要实现接口的所有方法,可以留给继承它的子类去实现它们。 抽象父类提供给子类一个方法,主要是起规范作用,你不写父类这个方法也行。
1069 0