1 public interface SpeakEnglish { 2 public abstract void speak(); 3 } 4 5 public abstract class Person { 6 private String name; 7 private int age; 8 public Person(){} 9 public Person(String name, int age) { 10 this.name = name; 11 this.age = age; 12 } 13 public String getName() { 14 return name; 15 } 16 public void setName(String name) { 17 this.name = name; 18 } 19 public int getAge() { 20 return age; 21 } 22 public void setAge(int age) { 23 this.age = age; 24 } 25 public abstract void eat(); 26 } 27 28 public abstract class Coach extends Person{ 29 public Coach() { 30 } 31 public Coach(String name, int age) { 32 super(name, age); 33 } 34 public abstract void teach(); 35 } 36 37 public abstract class Player extends Person{ 38 public Player() { 39 } 40 public Player(String name, int age) { 41 super(name, age); 42 } 43 public abstract void study(); 44 } 45 46 public class BasketballCoach extends Coach{ 47 public BasketballCoach() { 48 } 49 public BasketballCoach(String name, int age) { 50 super(name, age); 51 } 52 @Override 53 public void eat() { 54 System.out.println("篮球教练吃炒饭!"); 55 } 56 @Override 57 public void teach() { 58 System.out.println("篮球教练教运球和投篮!"); 59 } 60 } 61 62 public class BasketballPlayer extends Player{ 63 public BasketballPlayer() { 64 } 65 public BasketballPlayer(String name, int age) { 66 super(name, age); 67 } 68 @Override 69 public void eat() { 70 System.out.println("篮球运动员吃炒年糕"); 71 } 72 @Override 73 public void study() { 74 System.out.println("篮球运动员学习运球和投篮!"); 75 } 76 } 77 78 public class PingPangCoach extends Coach implements SpeakEnglish{ 79 public PingPangCoach() { 80 } 81 public PingPangCoach(String name, int age) { 82 super(name, age); 83 } 84 @Override 85 public void eat() { 86 System.out.println("乒乓球教练吃炒面"); 87 } 88 @Override 89 public void teach() { 90 System.out.println("乒乓球教练教发球和接球!"); 91 } 92 @Override 93 public void speak() { 94 System.out.println("乒乓球教练说英语"); 95 } 96 } 97 98 public class PingPangPlayer extends Player implements SpeakEnglish{ 99 public PingPangPlayer() { 100 } 101 public PingPangPlayer(String name, int age) { 102 super(name, age); 103 } 104 @Override 105 public void eat() { 106 System.out.println("乒乓球运动员吃炒粉丝"); 107 } 108 @Override 109 public void study() { 110 System.out.println("乒乓球运动员学习发球和接球"); 111 } 112 @Override 113 public void speak() { 114 System.out.println("乒乓球运动员说英语"); 115 } 116 } 117 118 //测试类 119 public class test { 120 public static void main(String[] args) { 121 //创建对象 122 PingPangPlayer ppp=new PingPangPlayer("王浩",30); 123 System.out.println(ppp.getName()+","+ppp.getAge()); 124 ppp.eat(); 125 ppp.study(); 126 ppp.speak(); 127 System.out.println("------------------"); 128 BasketballPlayer bp=new BasketballPlayer("姚明",40); 129 System.out.println(bp.getName()+","+bp.getAge()); 130 bp.eat(); 131 bp.study(); 132 } 133 }