写一个小的练习

学英语的接口

package lianxi;

public interface English {
    public abstract void speakenglish();
}

person基类

package lianxi;

public class Person {
    private String name;
    private int 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;
    }
    public Person(){

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

运动员类

package lianxi;

public abstract class Plater extends Person {
    public Plater() {
    }

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

    public abstract void study();

}

教练类

package lianxi;

public abstract class jiaolian extends Person{
    public jiaolian() {
    }

    public jiaolian(String name, int age) {
        super(name, age);
    }
    public abstract void teach();
}

乒乓运动员类

package lianxi;

public class pingpangplayer extends Plater implements English{

    public pingpangplayer() {
    }

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

    @Override
    public void speakenglish() {
        System.out.println("乒乓球运动员在学英语");
    }

    @Override
    public void study() {
        System.out.println("乒乓球运动员在学习乒乓球");
    }
}

乒乓教练类

package lianxi;

public class pingpangjiaolian extends jiaolian implements English{
    public pingpangjiaolian() {
    }

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

    @Override
    public void speakenglish() {
        System.out.println("乒乓球教练在学习英语");
    }

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

篮球运动员类

package lianxi;

public class lanqiuplayer extends Plater{
    public lanqiuplayer() {
    }

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

    @Override
    public void study() {
        System.out.println("篮球运动元"+super.getName()+"年龄为"+super.getAge()+"在的撒篮球");
    }
}

篮球教练类

package lianxi;

public class lanqiujiaolian extends jiaolian{
    public lanqiujiaolian() {
    }

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

    @Override
    public void teach() {
        System.out.println("篮球教练"+super.getName()+",年龄为"+super.getAge()+"在教打篮球");
    }
}

主类进行实现

package lianxi;

public class Tested {
    public static void main(String[] args){
        lanqiujiaolian l1=new lanqiujiaolian("张三",30);
        lanqiuplayer l2=new lanqiuplayer("李四",18);
        pingpangjiaolian p1=new pingpangjiaolian("迪迦",36);
        pingpangplayer p2=new pingpangplayer("郭永刚",18);
        l1.teach();
        l2.study();
        p1.speakenglish();
        p1.teach();
        p2.speakenglish();
        p2.study();
    }
}

posted on 2023-05-16 01:37  许七安gyg  阅读(16)  评论(0编辑  收藏  举报
$(document).ready(function() { // 禁止右键 $(document).bind("contextmenu", function(){return false;}); // 禁止选择 $(document).bind("selectstart", function(){return false;}); // 禁止Ctrl+C 和Ctrl+A $(document).keydown(function(event) { if ((event.ctrlKey&&event.which==67) || (event.ctrlKey&&event.which==86)) { //alert("对不起,版权所有,禁止复制"); return false; } }); });