PDI · Question #129
A lead developer creates an Apex interface called "Laptop". Consider the following code snippet: How can a developer use the Laptop Interface within the Silvertaptop class?
The correct answer is D. public class Silverlaptop implements Laptop. To use an Apex interface like Laptop within a class such as SilverLaptop, the class must explicitly implement that interface.
Question
A lead developer creates an Apex interface called "Laptop". Consider the following code snippet:
How can a developer use the Laptop Interface within the Silvertaptop class?
Options
- A@Extends(class=Laptop'')
- Bpublic calss SilverLaptop extends Laptop
- C@Interface (class=''Laptop'')
- Dpublic class Silverlaptop implements Laptop
How the community answered
(18 responses)- A6% (1)
- B6% (1)
- D89% (16)
Why each option
To use an Apex interface like `Laptop` within a class such as `SilverLaptop`, the class must explicitly `implement` that interface.
`@Extends` is not a valid Apex annotation or keyword for implementing interfaces.
The `extends` keyword is used for inheritance between classes (a class extending another class), not for implementing an interface.
`@Interface` is not a valid Apex annotation or keyword for implementing interfaces; it would be used to define an interface, not implement it.
In Apex, a class uses the `implements` keyword to indicate that it provides an implementation for all the methods declared in an interface. This establishes the contract that `SilverLaptop` will adhere to the `Laptop` interface's defined methods.
Concept tested: Apex interface implementation syntax
Source: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_interfaces.htm
Topics
Community Discussion
No community discussion yet for this question.