设计一个抽象类程序,Teacher抽象类和Student抽象类对person抽象类具有继承关系,计算机老师具体类和英语老师具体类对Teacher抽象类具有继承关系,英语学生具体类和计算机学生具体类对Student抽象类具有继承关系,英语老师具体类和英语学生具体类要实现口语考级接口
时间: 2024-02-15 18:36:49 浏览: 77
抽象类程序如下:
```
public abstract class Person {
private String name;
private int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public abstract void introduce();
}
public abstract class Teacher extends Person {
private String subject;
public Teacher(String name, int age, String subject) {
super(name, age);
this.subject = subject;
}
public abstract void teach();
}
public abstract class Student extends Person {
private int grade;
public Student(String name, int age, int grade) {
super(name, age);
this.grade = grade;
}
public abstract void study();
}
public interface OralExam {
public void oralExam();
}
public class ComputerTeacher extends Teacher {
public ComputerTeacher(String name, int age) {
super(name, age, "Computer");
}
@Override
public void introduce() {
System.out.println("I am a computer teacher.");
}
@Override
public void teach() {
System.out.println("I teach computer.");
}
}
public class EnglishTeacher extends Teacher implements OralExam {
public EnglishTeacher(String name, int age) {
super(name, age, "English");
}
@Override
public void introduce() {
System.out.println("I am an English teacher.");
}
@Override
public void teach() {
System.out.println("I teach English.");
}
@Override
public void oralExam() {
System.out.println("I can conduct oral exams for English learners.");
}
}
public class ComputerStudent extends Student {
public ComputerStudent(String name, int age, int grade) {
super(name, age, grade);
}
@Override
public void introduce() {
System.out.println("I am a computer student.");
}
@Override
public void study() {
System.out.println("I study computer.");
}
}
public class EnglishStudent extends Student implements OralExam {
public EnglishStudent(String name, int age, int grade) {
super(name, age, grade);
}
@Override
public void introduce() {
System.out.println("I am an English student.");
}
@Override
public void study() {
System.out.println("I study English.");
}
@Override
public void oralExam() {
System.out.println("I take oral exams for English proficiency.");
}
}
```
其中,Person抽象类表示人,Teacher和Student抽象类表示老师和学生,英语老师和英语学生需要实现OralExam接口,计算机老师和计算机学生不需要实现该接口。具体类ComputerTeacher、EnglishTeacher、ComputerStudent、EnglishStudent分别表示计算机老师、英语老师、计算机学生、英语学生。每个类都有自己的介绍方法,教学方法或学习方法,并且英语老师和英语学生都实现了OralExam接口的方法。
阅读全文