What is the output of the following Java program?
interface Discount { double apply(double price); }
public class Main {
public static void main(String[] args) {
Discount festival = new Discount() {
@Override
public double apply(double price) { return price * 0.8; }
};
Discount flat = price -> price - 50; // the same idea as a lambda
double p = 500;
System.out.println(festival.apply(p) + " " + flat.apply(p) + " " + flat.apply(festival.apply(p)));
}
}
The anonymous class and the lambda are two ways of creating an object that implements Discount.