黑马程序员技术交流社区
标题:
day09练习1
[打印本页]
作者:
gcno93
时间:
2016-9-6 22:22
标题:
day09练习1
需求一:
具体事物:基础班老师,就业班老师
共性:姓名,年龄,讲课。
特性:
基础班老师讲JavaSE
就业班老师讲Android
class Deom01 {
public static void main(String[] args) {
BaseTeacher bt = new BaseTeacher("你好",18);
bt.teach();
JiuYeTeacher jt=new JiuYeTeacher("再见",18);
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("我的姓名是:" + this.getName() + ",我的年龄是:" + this.getAge() + ",我是就业班老师讲是JavaSE");
}
}
class JiuYeTeacher extends Teacher {
public JiuYeTeacher(){} //空参
public JiuYeTeacher(String name,int age) {//有参
super(name,age);
}
public void teach() {
System.out.println("我的姓名是:" + this.getName() + ",我的年龄是:" + this.getAge() + ",我是就业班老师讲Android");
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2