PDI · Question #136
A developer must create a DrawList class that provides capabilities defined in the Sortable and Drawable interfaces. public interface Sortable { void sort(); } public interface Drawable { void…
The correct answer is C. Public class DrawList implements Sortable, Drawable { public void sort() { /*implementation*/}. To implement multiple interfaces in Apex, a class must use the implements keyword followed by a comma-separated list of interface names, and then provide concrete implementations for all methods defined in those interfaces.
Question
A developer must create a DrawList class that provides capabilities defined in the Sortable and Drawable interfaces. public interface Sortable { void sort(); } public interface Drawable { void draw(); } Which is the correct implementation?
Options
- APublic class DrawList implements Sortable, Implements Drawable { public void sort()
- BPublic class DrawList extends Sortable, Drawable {
- CPublic class DrawList implements Sortable, Drawable { public void sort() { /implementation/}
- DPublic class DrawList extends Sortable, extends Sortable, extends Drawable { public void sort()
How the community answered
(48 responses)- A2% (1)
- B2% (1)
- C92% (44)
- D4% (2)
Why each option
To implement multiple interfaces in Apex, a class must use the `implements` keyword followed by a comma-separated list of interface names, and then provide concrete implementations for all methods defined in those interfaces.
The `implements` keyword should only be used once in the class declaration, followed by a comma-separated list of all interfaces to be implemented.
The `extends` keyword is used for inheritance between classes, not for implementing interfaces, which requires the `implements` keyword.
The correct syntax for a class implementing multiple interfaces is to use the `implements` keyword once, followed by a comma-separated list of interface names, and then define all required methods from those interfaces.
The `extends` keyword is used incorrectly for interface implementation, and the syntax for listing multiple interfaces or superclasses is also incorrect.
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.