PDI · Question #111
A developer must implement a CheckPaymentProcessor class that provides check processing payment capabilities that adhere to what defined for payments in the PaymentProcessor interface. public…
The correct answer is B. Public class CheckPaymentProcessor implements PaymentProcessor { public void pay(Decimal. To implement an Apex interface, a class must use the implements keyword and provide a concrete definition for all methods declared in the interface.
Question
A developer must implement a CheckPaymentProcessor class that provides check processing payment capabilities that adhere to what 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?
Options
- APublic class CheckPaymentProcessor implements PaymentProcessor { public void pay(Decimal
- BPublic class CheckPaymentProcessor implements PaymentProcessor { public void pay(Decimal
- CPublic class CheckPaymentProcessor extends PaymentProcessor { public void pay(Decimal
- DPublic class CheckPaymentProcessor extends PaymentProcessor { public void pay(Decimal
How the community answered
(47 responses)- A4% (2)
- B91% (43)
- C2% (1)
- D2% (1)
Why each option
To implement an Apex interface, a class must use the `implements` keyword and provide a concrete definition for all methods declared in the interface.
While using `implements`, if the code snippet in the choice does not provide a concrete method body for the `pay` method, it would be an incomplete or incorrect implementation.
A class implements an interface using the `implements` keyword, and then must provide a concrete implementation (with a method body) for all methods declared in the interface, such as `public void pay(Decimal amount) { /* implementation */ }`.
The `extends` keyword is used for class inheritance, not for implementing interfaces in Apex.
The `extends` keyword is used for class inheritance, not for implementing interfaces in Apex.
Concept tested: Apex interface implementation syntax
Source: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_interfaces.htm
Topics
Community Discussion
No community discussion yet for this question.