PDI · Question #167
A developer must create a CreditcardPayment class that provides an implementation of an existing Payment class. Public virtual class Payment { public virtual void makePayment(Decimal amount) {…
The correct answer is A. Public class CreditcardPayment extends Payment {. To provide an implementation of an existing virtual class, a new class must use the extends keyword for inheritance.
Question
A developer must create a CreditcardPayment class that provides an implementation of an existing Payment class. Public virtual class Payment { public virtual void makePayment(Decimal amount) { /implementation/ } } Which is the correct implementation?
Options
- APublic class CreditcardPayment extends Payment {
- BPublic class CreditCardPayment implements Payment {
- CPublic class CreditCardPayment extends Payment {
- DPublic class CreditCardPayment implements Payment {
How the community answered
(50 responses)- A90% (45)
- B2% (1)
- C6% (3)
- D2% (1)
Why each option
To provide an implementation of an existing virtual class, a new class must use the `extends` keyword for inheritance.
Since `Payment` is declared as a `virtual class`, `CreditcardPayment` must use the `extends` keyword to inherit from it and provide its own implementation for the `makePayment` method.
The `implements` keyword is used when a class adopts an interface, not when it inherits from another class.
This choice has the correct `extends` keyword but is structurally incomplete as a full class definition, assuming the intent was to differentiate `extends` from `implements`.
The `implements` keyword is used for interfaces; attempting to implement a class will result in a compile-time error.
Concept tested: Apex Class Inheritance
Source: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_defining.htm
Topics
Community Discussion
No community discussion yet for this question.