题目是这张图片的内容,以下是代码实现:创建3个类,Student类,Teacher类,Main类,和1个接口
接口:
public interface Teach {
public abstract void teaching();
}Teacher类:public class Teacher implements Teach{
public Teacher(String name, String course) {
this.name = name;
this.course = course;
}
public Teacher() {
}
String name;
String course;
@Override
public void teaching() {
System.out.println("我是"+name +"老师,我教" +course +"学科"); }
}
Student类:public class Student extends Teacher{
String name;
int score;
public Student(String name, String course) {
super(name, course);
}
public Student() {
super();
}
public void getMyResult(){
System.out.println("我是学生"+this.name+",我的老师是"+super.name+",他教我"+super.course+"学科");
}
}
Main类:public class Main {
public static void main(String[] args) {
Teacher teacher = new Teacher("林宥嘉","音乐");
Student student = new Student("林宥嘉","音乐");
student.name = "邓紫棋";
student.score = 50;
teacher.teaching();
student.getMyResult();
if(student.score >= 60){
System.out.println("继续加油哦");
}else if(student.score<60){
System.out.println("成绩太低了,老师"+teacher.name+"让我回去罚写100遍");
}
}
}
|