运动员和教练的案例。
运动员和教练的案例。
篮球运动员和篮球教练,乒乓球运动员和乒乓秋教练.
因参加国际比赛,所有,篮球运动员和教练要学会一门外语.
//定义说英语的接口
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();
}
//定义教练(Coach)的抽象类
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.setName("邓亚萍");
ppp.setAge(50);
System.out.println(ppp.getName()+"***"+ppp.getAge());
ppp.eat();
ppp.study();
ppp.speak();
}
}
|
|