class Calculator { private interface Operation { public Long perform( Long x, Long y ); } private static Operation add = new Operation() { public Long perform( Long x, Long y ) { return x + y; } }; private static Operation subtract = new Operation() { public Long perform( Long x, Long y ) { return x - y; } }; private static Operation divide = new Operation() { public Long perform( Long x, Long y ) { return x / y; } }; private static Operation multiply = new Operation() { public Long perform( Long x, Long y ) { return x * y; } }; private static Long calculate( Operation op, Long x, Long y ) { return op.perform( x, y ); } private static class Addition implements Operation { public Long perform( Long x, Long y ) { return x + y; } } public static void main( String[] args ) { // System.out.println( calculate( add, 27L, 3L ) ); System.out.println( calculate( new Addition(), 27L, 3L ) ); System.out.println( calculate( subtract, 27L, 3L ) ); System.out.println( calculate( divide, 27L, 3L ) ); System.out.println( calculate( multiply, 27L, 3L ) ); } }