class BallTest
{
public static void main(String[] args)
{
PingPangAthlete pp = new PingPangAthlete();
pp.setName("邓亚萍");
pp.setAge(56);
System.out.println(pp.getName()+"****"+pp.getAge());
pp.eat();
pp.sleep();
pp.study();
pp.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;
}
//吃饭的方法
abstract void eat();
//睡觉的方法
public void sleep(){
System.out.println("睡觉");
}
}
//定义运动员Athlete的抽象类
abstract class Athlete extends Person
{
public Athlete(){}
//学习的方法
public abstract void study();
}
//定义教练(Coach)的抽象类
abstract class Coach extends Person
{
/**指导*/
public abstract void teach();
}
//乒乓球运动员类
class PingPangAthlete extends Athlete implements SpeakEnglish
{
public void speak(){
System.out.println("乒乓球运动员学习英语");
}
public void eat(){
System.out.println("乒乓球运动员吃米饭");
}
//学习的方法
public void study(){
System.out.println("乒乓球运动员学习打乒乓球");
}
}
//篮球球运动员类
class BasketAthlete extends Athlete
{
//学习的方法
public void study(){
System.out.println("乒乓球运动员学习打篮球");
}
public void eat(){
System.out.println("篮球球运动员吃牛肉面");
}
}
//乒乓球教练类
class PingPangCoach extends Coach implements SpeakEnglish
{
public void speak(){
System.out.println("乒乓球教练学习英语");
}
public void teach(){
System.out.println("乒乓球教练教打乒乓球");
}
public void eat(){
System.out.println("乒乓球教练吃鸡肉");
}
}
//蓝球教练类
class BasketCoach extends Coach
{
public void teach(){
System.out.println("乒乓球教练教打篮球");
}
public void eat(){
System.out.println("蓝球教练吃鸡肉");
}
}
//定义说英语的接口
interface SpeakEnglish
{
public abstract void speak();
} |
|