From 22375e25a11fa5029f6fe9c5a595b2ae99ed070a Mon Sep 17 00:00:00 2001 From: lee Date: Sun, 5 Dec 2021 19:49:45 +0000 Subject: [PATCH 1/3] =?UTF-8?q?=E7=BB=A7=E6=89=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/github/hcsp/inheritance/Animal.java | 23 +++++++++++++++++++ .../java/com/github/hcsp/inheritance/Cat.java | 11 ++++----- .../java/com/github/hcsp/inheritance/Dog.java | 10 ++++---- .../java/com/github/hcsp/inheritance/Rat.java | 12 +++++----- 4 files changed, 38 insertions(+), 18 deletions(-) create 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 new file mode 100644 index 0000000..41dae6a --- /dev/null +++ b/src/main/java/com/github/hcsp/inheritance/Animal.java @@ -0,0 +1,23 @@ +package com.github.hcsp.inheritance; + +public class Animal { + + private String name; + + public Animal(String name) { + this.name = name; + } + + public void sayMyName() { + System.out.println("我的名字是" + name); + } + + public void call(String voice) { + System.out.println(voice + name); + } + + + + + +} diff --git a/src/main/java/com/github/hcsp/inheritance/Cat.java b/src/main/java/com/github/hcsp/inheritance/Cat.java index f86dc38..d12232c 100644 --- a/src/main/java/com/github/hcsp/inheritance/Cat.java +++ b/src/main/java/com/github/hcsp/inheritance/Cat.java @@ -1,17 +1,16 @@ package com.github.hcsp.inheritance; -public class Cat { +public class Cat extends Animal{ private String name; public Cat(String name) { - this.name = name; + super(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..3849dd4 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) { - this.name = name; + super(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..7840e14 100644 --- a/src/main/java/com/github/hcsp/inheritance/Rat.java +++ b/src/main/java/com/github/hcsp/inheritance/Rat.java @@ -1,17 +1,17 @@ package com.github.hcsp.inheritance; -public class Rat { +public class Rat extends Animal{ private String name; + public Rat(String name) { - this.name = name; + super(name); } - public void sayMyName() { - System.out.println("我的名字是" + name); - } + public void zhizhi() { - System.out.println("吱吱" + name); + super.call("吱吱"); } + } From 286c52cb7b675ee3ff8456405762d0ace3c0f338 Mon Sep 17 00:00:00 2001 From: lee Date: Sun, 5 Dec 2021 20:06:53 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=E7=BB=A7=E6=89=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/github/hcsp/inheritance/Cat.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/github/hcsp/inheritance/Cat.java b/src/main/java/com/github/hcsp/inheritance/Cat.java index d12232c..063b31a 100644 --- a/src/main/java/com/github/hcsp/inheritance/Cat.java +++ b/src/main/java/com/github/hcsp/inheritance/Cat.java @@ -7,8 +7,6 @@ public Cat(String name) { super(name); } - - public void meow() { super.call("喵"); } From 9f3e985b1ec86a3c406af1e15d6cfe2da0840b71 Mon Sep 17 00:00:00 2001 From: lee Date: Sun, 5 Dec 2021 20:16:39 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=E7=BB=A7=E6=89=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/github/hcsp/inheritance/Cat.java | 1 - src/main/java/com/github/hcsp/inheritance/Dog.java | 1 - src/main/java/com/github/hcsp/inheritance/Rat.java | 2 -- 3 files changed, 4 deletions(-) diff --git a/src/main/java/com/github/hcsp/inheritance/Cat.java b/src/main/java/com/github/hcsp/inheritance/Cat.java index 063b31a..e53033c 100644 --- a/src/main/java/com/github/hcsp/inheritance/Cat.java +++ b/src/main/java/com/github/hcsp/inheritance/Cat.java @@ -1,7 +1,6 @@ package com.github.hcsp.inheritance; public class Cat extends Animal{ - private String name; public Cat(String name) { super(name); diff --git a/src/main/java/com/github/hcsp/inheritance/Dog.java b/src/main/java/com/github/hcsp/inheritance/Dog.java index 3849dd4..8841f76 100644 --- a/src/main/java/com/github/hcsp/inheritance/Dog.java +++ b/src/main/java/com/github/hcsp/inheritance/Dog.java @@ -1,7 +1,6 @@ package com.github.hcsp.inheritance; public class Dog extends Animal{ - private String name; public Dog(String name) { super(name); diff --git a/src/main/java/com/github/hcsp/inheritance/Rat.java b/src/main/java/com/github/hcsp/inheritance/Rat.java index 7840e14..ecd7cca 100644 --- a/src/main/java/com/github/hcsp/inheritance/Rat.java +++ b/src/main/java/com/github/hcsp/inheritance/Rat.java @@ -1,8 +1,6 @@ package com.github.hcsp.inheritance; public class Rat extends Animal{ - private String name; - public Rat(String name) { super(name);