LLD - Behavioral Design Patterns — Part 1
What will be printed when the following Java code executes?
interface Strategy { void execute(); }
class StrategyX implements Strategy { public void execute() { System.out.println("X"); } }
class StrategyY implements Strategy { public void execute() { System.out.println("Y"); } }
class Context {
private Strategy strategy;
public Context(Strategy strategy) { this.strategy = strategy; }
public void run() { strategy.execute(); }
}
public class Main {
public static void main(String[] args) {
Context context = new Context(new StrategyY());
context.run();
}
}