Salesforce Platform Developer I (legacy) — Question 110
A developer must implement a CheckPaymentProcessor class that provides check processing payment capabilities that adhere to what is defined for payments in the PaymentProcessor interface. public interface PaymentProcessor { void pay(Decimal amount);
}
Which is the correct implementation to use the PaymentProcessor interface class?
Answer options
- A. public class CheckPaymentProcessor implements PaymentProcessor { public void pay(Decimal amount);
- B. public class CheckPaymentProcessor implements PaymentProcessor { public void pay(Decimal amount){}
- C. public class CheckPaymentProcessor extends PaymentProcessor { public void pay(Decimal amount){}
- D. public class CheckPaymentProcessor extends PaymentProcessor { public void pay(Decimal amount);
Correct answer: B
Explanation
Option B is correct because it properly implements the PaymentProcessor interface by providing a concrete implementation for the pay method, which includes an empty body. Option A is incorrect because it lacks the method body, making it an incomplete implementation. Options C and D are wrong because they incorrectly use 'extends' instead of 'implements' for an interface, which is not allowed in Java.