据需求,完成如下代码(按照标准格式写),并在测试类中进行测试。
需求一:
具体事物:基础班老师,就业班老师
共性:姓名,年龄,讲课。
特性:
基础班老师讲JavaSE
就业班老师讲Android
class Text_Teacher {
public static void main(String[] args) {
BaseTeacher bt = new BaseTeacher("张三",28);
System.out.println(bt.getName()+" "+bt.getAge());
bt.teach();
JiuTeacher jt = new JiuTeacher("李四",29);
System.out.println(jt.getName()+" "+jt.getAge());
jt.teach();
}
}
abstract class Teacher{
private String name;
private int age;
public Teacher(){}
public Teacher(String name,int age){
this.name = name;
this.age = age;
}
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
public void setAge(int age){
this.age = age;
}
public int getAge(){
return age;
}
public abstract void teach();
}
class BaseTeacher extends Teacher{
public BaseTeacher(){}
public BaseTeacher(String name,int age){
super(name,age);
}
public void teach(){
System.out.println("基础班老师讲JavaSE");
}
}
class JiuTeacher extends Teacher{
public JiuTeacher(){}
public JiuTeacher(String name,int age){
super(name,age);
}
public void teach(){
System.out.println("就业班老师讲Andriod");
}
}
|
|