Skip to content

Commit

Permalink
Geng geng geng (#253)
Browse files Browse the repository at this point in the history
Geng geng geng (#253)
  • Loading branch information
leoleepsyche authored Dec 5, 2021
1 parent df905d3 commit c374f7a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 22 deletions.
23 changes: 23 additions & 0 deletions src/main/java/com/github/hcsp/inheritance/Animal.java
Original file line number Diff line number Diff line change
@@ -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);
}





}
12 changes: 4 additions & 8 deletions src/main/java/com/github/hcsp/inheritance/Cat.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package com.github.hcsp.inheritance;

public class Cat {
private String name;
public class Cat extends Animal{

public Cat(String name) {
this.name = name;
}

public void sayMyName() {
System.out.println("我的名字是" + name);
super(name);
}

public void meow() {
System.out.println("喵" + name);
super.call("喵");
}

}
11 changes: 4 additions & 7 deletions src/main/java/com/github/hcsp/inheritance/Dog.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package com.github.hcsp.inheritance;

public class Dog {
private String name;
public class Dog extends Animal{

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("汪");
}
}
12 changes: 5 additions & 7 deletions src/main/java/com/github/hcsp/inheritance/Rat.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.github.hcsp.inheritance;

public class Rat {
private String name;
public class Rat extends Animal{

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("吱吱");
}

}

0 comments on commit c374f7a

Please sign in to comment.