interface

public interface Printer {
    void print();
}


/***********************************/


public class ColorfulPrinter implements Printer{
    @Override
    public void print() {
        System.out.println("this is colorful printer!!!");
    }
}


/***********************************/


public class BlackWhitePrinter implements Printer{
    @Override
    public void print() {
        System.out.println("this is black white printer!!!");
    }
}

/***********************************/

public class T {


    public static void main(String[] args) {
        Printer cp = new ColorfulPrinter();
Printer bp
= new BlackWhitePrinter();
Printer ap
= new Printer() { @Override public void print() { System.out.println("this is anonymous printer"); } };
Printer lp
= () -> System.out.println("this is anonymous printer"); cp.print(); bp.print(); ap.print(); lp.print(); } }

 

posted @ 2021-07-21 20:38  Tudoo  阅读(43)  评论(0编辑  收藏  举报