练习要求
老师案例:
具体事物:基础班老师,就业班老师
共性:姓名、年龄、讲课
实现代码
abstract class Teacher{
private int age;
private String name;
public Teacher(String name, int age){
this.name = name;
this.age = age;
}
public void show(){
System.out.println("name= "+name+" age="+age);
}
public abstract void lesson();
public abstract void teach();
}
class BaseTeacher extends Teacher{
public BaseTeacher(String name, int age){
super(name, age);
}
public void lesson(){
System.out.println("基础班老师");
}
public void teach(){
System.out.println("JavaSe基础");
}
}
class EmploymentTeacher extends Teacher{
public EmploymentTeacher(String name, int age){
super(name, age);
}
public void lesson(){
System.out.println("就业班老师");
}
public void teach(){
System.out.println("Java的项目");
}
}
class AbstractDemo4{
public static void main(String[] args){
print(new BaseTeacher("xyz", 18));
print(new EmploymentTeacher("la", 19));
}
public static void print (Teacher t){
t.lesson();
t.teach();
}
}
输出结果