(1)定义一个学习接口,Studylnterface,提供两个方法:上课attendClass,考试exam。 (2)定义一个学生抽象类Student,Student实现Studylnterface接口,重写考试exam方法,输出:“在学校参加期末考试”,自行设计学生类其他信息。 (3)定义两个子类:大学生类CollegeStudent和在职研究生类JobGraduateStudent继承抽象类Student.重写上课attendClass方法:大学生类输出“在学校教室上课”,在职研究生类输出“在网上上课”,在职研究生类提供一个描述工作的work方法。 (4)编写测试类,建立大学生类和在职研究生类对象,调用对象的所有方法进行测试。 要求:提交代码截图和测试结果截图。
时间: 2024-03-25 21:42:03 浏览: 23
抱歉,作为一个语言模型AI,我无法截图,请您自行测试代码并截图。
以下是代码示例:
```
interface Studylnterface {
void attendClass();
void exam();
}
abstract class Student implements Studylnterface {
String name;
int age;
public Student(String name, int age) {
this.name = name;
this.age = age;
}
@Override
public void exam() {
System.out.println("在学校参加期末考试");
}
}
class CollegeStudent extends Student {
public CollegeStudent(String name, int age) {
super(name, age);
}
@Override
public void attendClass() {
System.out.println("在学校教室上课");
}
}
class JobGraduateStudent extends Student {
public JobGraduateStudent(String name, int age) {
super(name, age);
}
@Override
public void attendClass() {
System.out.println("在网上上课");
}
public void work() {
System.out.println("正在工作");
}
}
public class Test {
public static void main(String[] args) {
CollegeStudent collegeStudent = new CollegeStudent("小明", 20);
JobGraduateStudent jobGraduateStudent = new JobGraduateStudent("小红", 25);
collegeStudent.attendClass();
collegeStudent.exam();
jobGraduateStudent.attendClass();
jobGraduateStudent.exam();
jobGraduateStudent.work();
}
}
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)