diff --git a/src/main/java/com/github/hcsp/inheritance/Cat.java b/src/main/java/com/github/hcsp/inheritance/Cat.java index f86dc38..7a50e63 100644 --- a/src/main/java/com/github/hcsp/inheritance/Cat.java +++ b/src/main/java/com/github/hcsp/inheritance/Cat.java @@ -1,17 +1,15 @@ package com.github.hcsp.inheritance; -public class Cat { +public class Cat extends Animal{ + private String name; public Cat(String name) { + super(name); this.name = name; } - public void sayMyName() { - System.out.println("我的名字是" + name); - } - public void meow() { - System.out.println("喵" + name); + super.call("喵" ); } } diff --git a/src/main/java/com/github/hcsp/inheritance/Dog.java b/src/main/java/com/github/hcsp/inheritance/Dog.java index 24e713a..282f907 100644 --- a/src/main/java/com/github/hcsp/inheritance/Dog.java +++ b/src/main/java/com/github/hcsp/inheritance/Dog.java @@ -1,17 +1,15 @@ package com.github.hcsp.inheritance; -public class Dog { +public class Dog extends Animal { private String name; public Dog(String name) { + super(name); this.name = name; } - public void sayMyName() { - System.out.println("我的名字是" + name); - } public void wang() { - System.out.println("汪" + name); + super.call("汪"); } } diff --git a/src/main/java/com/github/hcsp/inheritance/Rat.java b/src/main/java/com/github/hcsp/inheritance/Rat.java index bc517d1..50da430 100644 --- a/src/main/java/com/github/hcsp/inheritance/Rat.java +++ b/src/main/java/com/github/hcsp/inheritance/Rat.java @@ -1,17 +1,16 @@ package com.github.hcsp.inheritance; -public class Rat { +public class Rat extends Animal { private String name; public Rat(String name) { + super(name); this.name = name; } - public void sayMyName() { - System.out.println("我的名字是" + name); - } public void zhizhi() { - System.out.println("吱吱" + name); + super.call("吱吱"); } + }