-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
36 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("喵"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("汪"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("吱吱"); | ||
} | ||
|
||
} |