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(); } }