Which of the following is the correct way to declare a payment strategy interface method in Java?
easy📝 Conceptual Q3 of 15
LLD - Design — Online Shopping Cart
Which of the following is the correct way to declare a payment strategy interface method in Java?
Apublic pay(double amount);
Bvoid pay(double amount) {}
Cpublic void pay(double amount);
Dvoid pay(double amount) => {}
Step-by-Step Solution
Solution:
Step 1: Recall Java interface method syntax
Interface methods are public and abstract by default and declared without a body.
Step 2: Check each option
public void pay(double amount); correctly declares a public method without body. void pay(double amount) {} has body which is invalid in interface without default. public pay(double amount); misses return type. void pay(double amount) => {} uses invalid syntax.
Final Answer:
public void pay(double amount); -> Option C
Quick Check:
Java interface method syntax = public void pay(double amount); [OK]
Quick Trick:Interface methods have no body and are public by default [OK]
Common Mistakes:
Adding method body in interface without default
Omitting return type
Using arrow syntax in Java
Master "Design — Online Shopping Cart" in LLD
9 interactive learning modes - each teaches the same concept differently