// 定义说英语的接口
interface SpeakEnglish{
public abstract void speak();
}
// 定义人的抽象类
abstract class Person
{
private String name;
private int age;
public Person(){}
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
public void setAge(int age ){
this.age = age;
}
public int getAge(){
return age;
}
//定义睡觉的方法
public void sleep(){
System.out.println("睡觉");
}
//定义吃饭的方法
public abstract void eat();
}
// 定义运动员的抽象类
abstract class Player extends Person {
public Player(){}
public abstract void study();
}
// 定义教练的抽象类
abstract class Coach extends Person{
public Coach(){}
//教练的方法
public abstract void teach();
}
// 乒乓球运动员类
class PingPangPlayer extends Player implements SpeakEnglish{
public PingPangPlayer(){}
public void speak(){
System.out.println("说英语");
}
public void eat(){
System.out.println("吃肉");
}
public void study(){
System.out.println("学习打球");
}
}
// 篮球运动员类
class BasketPlayer extends Player{
public BasketPlayer(){}
public void eat(){
System.out.println("吃面");
}
public void study(){
System.out.println("学习打球");
}
}
// 乒乓球教练类
class PingPangCoach extends Coach implements SpeakEnglish{
public PingPangCoach(){}
public void speak(){
System.out.println("说英语");
}
public void eat(){
System.out.println("大口吃肉");
}
public void teach(){
System.out.println("教人打球");
}
}
// 篮球教练类
class BasketCoach extends Coach{
public BasketCoach(){}
public void eat(){
System.out.println("大口吃饭");
}
public void teach(){
System.out.println("教人打球");
}
}
class PersonTest{
public static void main(String[]args){
PingPangPlayer ppp = new PingPangPlayer();
ppp.study();
ppp.eat();
ppp.speak();
}
} |