abstract class Person
{
private String name;
private int age;
public Person(){}
public Person(String name,int age)
{
this.name = name;
this.age = age;
}
public void setAge(int age)
{
this.age = age;
}
public int getAge()
{
return age;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void sleep()
{
System.out.println("困了去睡觉了");
}
public abstract void eat();
interface English
{
public abstract void speak();
}
}
//在定义运动员类,他们有各自的方法练习,定义为抽象类,继承(人)类中的睡觉,
abstract class Athlete extends Person
{
public abstract void practice();
}
//在定义教练类,他们有各自的方法训练,定义为抽象类,继承(人)类中的睡觉
abstract class Drill extends Person
{
public abstract void train();
}
//定义乒乓球运动员类继承运动员类,覆盖吃饭,练习,学习英语
class PingpangqiuAthlete extends Athlete implements English
{
public void practice()
{
System.out.println("练习乒乓球接球");
}
public void eat()
{
System.out.println("每顿饭能吃俩鸡蛋一个饼");
}
public void speak()
{
System.out.println("乒乓球运动员学习说英语");
}
}
//定义蓝球运动员类继承运动员类,覆盖吃饭,练习。
class LanqiuAthlete extends Athlete
{
public void practice()
{
System.out.println("篮球运动员练习扣篮");
}
public void eat()
{
System.out.println("篮球运动员吃一个恐龙蛋");
}
}
//定义乒乓球教练类继承教练类,覆盖吃饭,练习,学习英语
class PingpangqiuqiuDrill extends Drill
{
public void train()
{
System.out.println("乒乓球教练训练接球");
}
public void eat()
{
System.out.println("乒乓球教练吃俩鹌鹑蛋一个雪米饼");
}
}
//定义蓝球教练类继承教练类,覆盖吃饭,练习。
class LanqiuDrill extends Drill
{
public void train()
{
System.out.println("教练训练扣篮");
}
public void eat()
{
System.out.println("蓝球教练吃一个饼");
}
}
class PersonTset
{
public static void main(String[] args)
{
System.out.println("首先介绍乒乓球运动员");
System.out.println("*****");
System.out.println("*****");
Athlete ppp = new PingpangqiuAthlete();
ppp.setName("邓亚萍");
ppp.setAge(20);
System.out.println("运动员"+ppp.getName()+"今年"+ppp.getAge()+"岁了");
ppp.speak();
ppp.practice();
ppp.eat();
ppp.sleep();
System.out.println("下面介绍乒乓球教练");
System.out.println("*****");
System.out.println("*****");
Drill jjj = new PingpangqiuqiuDrill();
jjj.setName("莫文蔚");
jjj.setAge(40);
System.out.println("教练"+jjj.getName()+"今年"+jjj.getAge()+"岁了");
jjj.train();
jjj.eat();
jjj.sleep();
System.out.println("下面介绍篮球运动员");
System.out.println("*****");
System.out.println("*****");
Athlete lll = new LanqiuAthlete();
lll.setName("姚明");
lll.setAge(30);
System.out.println("运动员"+lll.getName()+"今年"+lll.getAge()+"岁了");
lll.practice();
lll.eat();
lll.sleep();
System.out.println("下面介绍篮球教练");
System.out.println("*****");
System.out.println("*****");
Drill ljj = new LanqiuDrill();
ljj.setName("刘德华");
ljj.setAge(50);
System.out.println("教练"+ljj.getName()+"今年"+ljj.getAge()+"岁了");
ljj.train();
ljj.eat();
ljj.sleep();
}
} |
|