??????????java???????????
???????????? ???????[ 2014/8/13 16:56:11 ] ??????????????? Java
//????Gun??
public abstract class Gun {
protected String name;
// ?????????????????????????????????????????
public Gun() {
public Gun(String name) {
this.name = name;
// ????????????????????м?к???塣
abstract void sound();
public String getName() {
return name;
public void setName(String name) {
this.name = name;
//Carbine?????Gun
public class Carbine extends Gun {
//?????????????????????????????????????????
public Carbine(String name) {
this.name = name;
//Gun???2????????????????sound()???????????????????????sound()??????????????Gun???????????????????
//???????Java???????
void sound() http://www.huiyi8.com/jiaoben/
// TODO Auto-generated method stub
System.out.println("DaDaDa!"); javascript
//Rifle?????Gun
public class Rifle extends Gun {
//???????????????????????????????????????????
public Rifle(String name) {
this.name = name;
//Gun???2????????????????sound()???????????????????????sound()??????????????Gun???????????????????
//???????Java???????
void sound() {
// TODO Auto-generated method stub
System.out.println("Peng! Peng! Peng!");
//????Person??
public class Person {
private String name;
public String getName() {
return name;
public void setName(String name) {
this.name = name;
// ?????????
public void shoot(Person p?? Gun g) {
System.out.println(this.name + " shoot " + p.getName() + " using a "
+ g.getName());
g.sound();
//??main()?????в???
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Person p1 = new Person();
Person p2 = new Person();
p1.setName("XiaoWang");
p2.setName("XiaoLi");
Rifle r = new Rifle("rifle");
Carbine c = new Carbine("carbine");
// ??????????ú???????????????Ч????
p1.shoot(p2?? r);
p1.shoot(p2?? c);
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11