Describe a scenario where a functional interface was the best solution.

A functional interface is the best choice when a piece of behavior needs to be passed as an argument rather than creating separate classes for every implementation. It is especially useful for callbacks, event handling, task execution, and custom business rules where only a single abstract method is required. Combined with lambda expressions, it makes the code concise, readable, and easy to maintain.

Key Points

Example

Consider an e-commerce application where different discount strategies must be applied to orders. Instead of creating multiple classes such as FestivalDiscount, PremiumCustomerDiscount, and CouponDiscount, a functional interface can be used to pass the discount logic dynamically.

@FunctionalInterface
interface DiscountStrategy {

    double applyDiscount(double amount);
}

public class OrderService {

    public static void main(String[] args) {

        DiscountStrategy festivalDiscount =
                amount -> amount * 0.90;

        double finalAmount =
                festivalDiscount.applyDiscount(1000);

        System.out.println(
                "Final Amount: "
                        + finalAmount);
    }
}

Interview Tip

A concise interview answer is: A functional interface is ideal when a single piece of behavior needs to be passed dynamically. For example, in an e-commerce application, I can use a functional interface with lambda expressions to implement different discount strategies without creating multiple classes, resulting in cleaner, more flexible, and maintainable code.

Last updated: 16 July 2026

Previous question: How would you design a system that supports different payment methods (credit card, PayPal, cryptocurrencies) using interfaces and abstract classes?

Next question: How would you analyze and debug memory leaks in Java?

More Core Java - Level V (Expert) interview questions

All Core Java - Level V (Expert) questions