/*
乒乓球运动员和教练
篮球运动员和教练
所有的人都需要吃饭
为了出国交流,乒乓球运动员和教练需要说英语
请用所学的知识分析这里应该有哪些类抽象类和接口
*/
//定义一个说英语的接口
interface SpeakEnglish
{
public abstract void speak();
}
class GameDemo
{
public static void main(String[]args)
{
PingpangPlayer ppp=new PingpangPlayer();
ppp.eat();
ppp.speak();
ppp.study();
ppp.sleep();
ppp.setName("高海亮");
ppp.setAge(12);
System.out.println("姓名: "+ppp.getName()+" 年龄 "+ppp.getAge());
System.out.println("-------------------------------------");
BasketCoach bc=new BasketCoach();
bc.eat();
//ppp.speak();
bc.teach();
bc.sleep();
bc.setName("小帅哥");
bc.setAge(123);
System.out.println("姓名: "+bc.getName()+" 年龄 "+bc.getAge());
}
}
//人的类
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 JiaoLian extends Person
{
public JiaoLian(){}
public abstract void teach();
}
//定义一个乒乓球运动员类
class PingpangPlayer extends Player implements SpeakEnglish
{
public PingpangPlayer(){}
public void study()
{
System.out.println("乒乓球运动员学习推挡");
}
public void eat()
{
System.out.println("乒乓球运动员吃泡面");
}
public void speak()
{
System.out.println("乒乓球运动员需要学习英语");
}
}
//定义一个篮球运动员类
class BasketPlayer extends Player
{
public BasketPlayer(){}
public void study()
{
System.out.println("蓝球运动员学习运球");
}
public void eat()
{
System.out.println("蓝球运动员吃牛肉");
}
}
//定义一个乒乓球教练类
class PingPangCoach extends JiaoLian implements SpeakEnglish
{
public PingPangCoach(){}
public void teach()
{
System.out.println("乒乓球教练教推挡");
}
public void eat()
{
System.out.println("乒乓球教练爱吃老婆做的饭");
}
public void speak()
{
System.out.println("乒乓球教练需要学习英语交流");
}
}
//定义一个篮球教练类
class BasketCoach extends JiaoLian
{
public BasketCoach(){}
public void teach()
{
System.out.println("蓝球教练教运球");
}
public void eat()
{
System.out.println("蓝球教练爱吃自己做的饭");
}
}
|
|