From df905d3f437b177133837ca13f6b14778b6d2edc Mon Sep 17 00:00:00 2001 From: Hcsp Bot Date: Mon, 22 Nov 2021 01:33:30 +0000 Subject: [PATCH] =?UTF-8?q?Revert=20"=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E7=88=B6=E7=B1=BB=E6=9D=A5=E7=BB=A7=E6=89=BF=20(#247)"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 1733d77876c51547ef4027872a305326b135393c. --- src/main/java/com/github/hcsp/inheritance/Animal.java | 9 --------- src/main/java/com/github/hcsp/inheritance/Cat.java | 7 ++++++- src/main/java/com/github/hcsp/inheritance/Dog.java | 7 ++++++- src/main/java/com/github/hcsp/inheritance/Rat.java | 9 +++++++-- 4 files changed, 19 insertions(+), 13 deletions(-) delete mode 100644 src/main/java/com/github/hcsp/inheritance/Animal.java diff --git a/src/main/java/com/github/hcsp/inheritance/Animal.java b/src/main/java/com/github/hcsp/inheritance/Animal.java deleted file mode 100644 index 0690b06..0000000 --- a/src/main/java/com/github/hcsp/inheritance/Animal.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.hcsp.inheritance; - -public class Animal { - protected String name; - - public void sayMyName() { - System.out.println("我的名字是" + name); - } -} diff --git a/src/main/java/com/github/hcsp/inheritance/Cat.java b/src/main/java/com/github/hcsp/inheritance/Cat.java index cb5212c..f86dc38 100644 --- a/src/main/java/com/github/hcsp/inheritance/Cat.java +++ b/src/main/java/com/github/hcsp/inheritance/Cat.java @@ -1,11 +1,16 @@ package com.github.hcsp.inheritance; -public class Cat extends Animal{ +public class Cat { + private String name; public Cat(String name) { this.name = name; } + public void sayMyName() { + System.out.println("我的名字是" + name); + } + public void meow() { System.out.println("喵" + name); } diff --git a/src/main/java/com/github/hcsp/inheritance/Dog.java b/src/main/java/com/github/hcsp/inheritance/Dog.java index 81d3979..24e713a 100644 --- a/src/main/java/com/github/hcsp/inheritance/Dog.java +++ b/src/main/java/com/github/hcsp/inheritance/Dog.java @@ -1,11 +1,16 @@ package com.github.hcsp.inheritance; -public class Dog extends Animal{ +public class Dog { + private String name; public Dog(String name) { this.name = name; } + public void sayMyName() { + System.out.println("我的名字是" + name); + } + public void wang() { System.out.println("汪" + name); } diff --git a/src/main/java/com/github/hcsp/inheritance/Rat.java b/src/main/java/com/github/hcsp/inheritance/Rat.java index d5615b1..bc517d1 100644 --- a/src/main/java/com/github/hcsp/inheritance/Rat.java +++ b/src/main/java/com/github/hcsp/inheritance/Rat.java @@ -1,9 +1,14 @@ package com.github.hcsp.inheritance; -public class Rat extends Animal{ +public class Rat { + private String name; public Rat(String name) { - super.name = name; + this.name = name; + } + + public void sayMyName() { + System.out.println("我的名字是" + name); } public void zhizhi() {