package com.study.exception.demo08;
public interface SpeakEnglish {
void speakEnglish();
}
package com.study.exception.demo08;
public abstract class Person {
private int age;
private String name;
public Person() {
}
public Person(int age, String name) {
this.age = age;
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public abstract void eat();
}
package com.study.exception.demo08;
public abstract class Coach extends Person{
public Coach() {
}
public Coach(int age, String name) {
super(age, name);
}
public abstract void teach();
}
package com.study.exception.demo08;
public abstract class Player extends Person{
public Player() {
}
public Player(int age, String name) {
super(age, name);
}
public abstract void exercise();
}
package com.study.exception.demo08;
public class BasketballCoach extends Coach{
public BasketballCoach() {
}
public BasketballCoach(int age, String name) {
super(age, name);
}
@Override
public void teach() {
System.out.println("篮球教练教篮球");
}
@Override
public void eat() {
System.out.println("篮球教练吃饭");
}
}
package com.study.exception.demo08;
public class BasketballPlayer extends Player{
public BasketballPlayer() {
}
public BasketballPlayer(int age, String name) {
super(age, name);
}
@Override
public void exercise() {
System.out.println("篮球运动员练习篮球");
}
@Override
public void eat() {
System.out.println("篮球运动员吃饭");
}
}
package com.study.exception.demo08;
public class PingpangCoach extends Coach implements SpeakEnglish{
public PingpangCoach() {
}
public PingpangCoach(int age, String name) {
super(age, name);
}
@Override
public void teach() {
System.out.println("乒乓球教练教乒乓球");
}
@Override
public void eat() {
System.out.println("乒乓球教练吃饭");
}
@Override
public void speakEnglish() {
System.out.println("乒乓球教练说英语");
}
}
package com.study.exception.demo08;
public class PingpangPlayer extends Player implements SpeakEnglish{
public PingpangPlayer() {
}
public PingpangPlayer(int age, String name) {
super(age, name);
}
@Override
public void exercise() {
System.out.println("乒乓球运动员练习乒乓球");
}
@Override
public void eat() {
System.out.println("乒乓球运动员吃饭");
}
@Override
public void speakEnglish() {
System.out.println("乒乓球运动员说英语");
}
}
package com.study.exception.demo08;
//测试类
public class DemoTest {
public static void main(String[] args) {
PingpangPlayer pp = new PingpangPlayer();
pp.setAge(18);
pp.setName("张三");
System.out.println(pp.getName() + "," + pp.getAge());
pp.speakEnglish();
pp.exercise();
pp.eat();
System.out.println("----------------------");
BasketballPlayer bp = new BasketballPlayer(20,"李四");
System.out.println(bp.getAge() + "," + bp.getName());
bp.exercise();
bp.eat();
}
}