Bird
0
0

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:
  1. Step 1: Recall Java interface method syntax

    Interface methods are public and abstract by default and declared without a body.
  2. 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.
  3. Final Answer:

    public void pay(double amount); -> Option C
  4. 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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes