12.抽象类案例(老师)
作者:
今天庹 | 来源:发表于
2018-09-24 17:20 被阅读0次
老师案例:
老师类:
基础班老师:
实验班老师:
package com.itheima_2;
/*
* 普通班老师,实验班老师
*
* 共性:
* 属性 姓名,年龄,性别
* 行为 讲课,唱歌
*/
public class AbstractTest {
public static void main(String[] args) {
BasicTeacher bt = new BasicTeacher();
bt.name = "张三";
bt.teach();
SuperTeacher st = new SuperTeacher();
st.name = "李四";
st.teach();
}
}
abstract class Teacher {
String name;//姓名
int age;//年龄
String gender;//性别
//讲课
public abstract void teach();
}
class BasicTeacher extends Teacher {
@Override
public void teach() {
System.out.println(name + "讲普通班课程");
}
}
class SuperTeacher extends Teacher {
@Override
public void teach() {
System.out.println(name + "讲实验班课程");
}
}
本文标题:12.抽象类案例(老师)
本文链接:https://www.haomeiwen.com/subject/xkqhoftx.html
网友评论