Java-19.1 教练运动员案例

2021/10/9 11:38:24

本文主要是介绍Java-19.1 教练运动员案例,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

 

 

//人抽象类
abstract class Person {
    private String name;
    private int age;


    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
//教练抽象类
abstract class Coach extends Person {
    public Coach() {
    }

    public Coach(String name, int age) {
        super(name, age);
    }

    public abstract void work();
}
//运动员抽象类
abstract class SportsMan extends Person {
    public SportsMan() {
    }

    public SportsMan(String name, int age) {
        super(name, age);
    }

    public abstract void work();
}
//乒乓球运动员
public class PingPang extends SportsMan implements LeanEnglish{
    public PingPang() {
    }

    public PingPang(String name, int age) {
        super(name, age);
    }

    @Override
    public void work() {
        System.out.println("乒乓运动员");
    }


    @Override
    public void show() {
        System.out.println("学英语出国");
    }
}
//篮球运动员
public class Basketball extends SportsMan{
    public Basketball() {
    }

    public Basketball(String name, int age) {
        super(name, age);
    }

    @Override
    public void work() {
        System.out.println("篮球运动员");
    }


}
//乒乓球教练
public class Pcoach extends Coach implements LeanEnglish{
    public Pcoach() {
    }

    public Pcoach(String name, int age) {
        super(name, age);
    }

    @Override
    public void work() {
        System.out.println("乒乓球教练");
    }


    @Override
    public void show() {
        System.out.println("学英语出国");
    }
}
//篮球教练
public class Bcoach extends Coach {
    public Bcoach() {
    }

    public Bcoach(String name, int age) {
        super(name, age);
    }

    @Override
    public void work() {
        System.out.println("篮球教练");
    }


}
//学习英语接口
public interface LeanEnglish {
    public abstract void show();
}
/*教练和运动员案例(学生分析然后讲解)
        乒乓球运动员和篮球运动员。
        乒乓球教练和篮球教练。
        为了出国交流,跟乒乓球相关的人员都需要学习英语。
        请用所学知识:
        分析,这个案例中有哪些抽象类,哪些接口,哪些具体类。*/
public class MainText {
    public static void main(String[] args) {
        SportsMan sm = new PingPang("张三", 20);
        Coach c = new Pcoach("李四", 25);
        ((PingPang) sm).show();
        sm.work();

        c.work();
        ((Pcoach) c).show();

    }
}

 



这篇关于Java-19.1 教练运动员案例的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程