java4android (被客户不断变化的需求“折磨”)

时间:2014-05-27 02:00:57   收藏:0   阅读:395

父类:

bubuko.com,布布扣
class Printer{
    void open(){
        System.out.print("Open");
    }
    
    void close(){
        System.out.print("close");
    }
    
    void print(String print){
        System.out.print("print-->"+print);
    }
}
bubuko.com,布布扣

子类:

bubuko.com,布布扣
class HPPrinter extends Printer{
    
}
bubuko.com,布布扣
bubuko.com,布布扣
class CanonPrinter extends Printer{
    
    void close(){
        this.clean();
        super.close();
    }
    
    void clean(){
        System.out.print("clean");
    }
}
bubuko.com,布布扣

主函数:

bubuko.com,布布扣
class Test{
    public static void main(String args[]){
        int flag = 0;
        
        if(flag == 0){
            HPPrinter hpPrinter = new HPPrinter();
            hpPrinter.open();
            hpPrinter.print("bvc");
            hpPrinter.close();
        }
        else if(flag == 1){
            CanonPrinter canonPriter = new CanonPrinter();
            canonPriter.open();
            canonPriter.print("bvc");
            canonPriter.close();
        
         }
    }
}
bubuko.com,布布扣

 

 

java4android (被客户不断变化的需求“折磨”),布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!