我与咖啡娘的爱恨情仇

12.抽象类案例(老师)

2018-09-24  本文已影响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 + "讲实验班课程");
    }
}
上一篇 下一篇

猜你喜欢

热点阅读