29.2k views
5 votes
When a class implements an interface, it:

A. Agrees to provide all the methods and/or properties specified by the interface.
B. Agrees to provide all the methods but not the properties specified by the interface.
C. Agrees to provide all the properties but not the methods specified by the interface.
D. None of these statements are true.

User Wutzebaer
by
8.1k points

1 Answer

3 votes

Final answer:

A. Agrees to provide all the methods and/or properties specified by the interface. A class implementing an interface must adhere to the contract of providing implementations for all the methods

Step-by-step explanation:

When a class implements an interface, it: A. Agrees to provide all the methods and/or properties specified by the interface. This means that the implementing class is under contract to define all the functionalities declared in the interface, ensuring that it conforms to a specific behavior or API.

An interface typically contains method signatures and sometimes properties, constants or other elements, depending on the programming language in use.

For instance, in Java or C#, a class implementing an interface must provide concrete implementations for all of the interface's methods. However, this could vary depending on the language as, for example, in PHP, interfaces can also contain constants but not properties.

User Leonardkraemer
by
7.8k points