If a class is using an interface, it must

user2140173

If a class is using an interface, it must:

  • (1) inherit the properties of the interface

  • (2) contain the same methods as the interface

  • (3) create an interface object

  • (4) all of the above

And the correct answer is (4)all of the above.

Note: this comes from here and I have no idea who actually is the author of the question.

I agree to the (1)st and (2)nd, but I would argue over the wording of the (3)rd.

I guess it could be dually interpreted;

Create an interface object could mean just an instance of a class that inherits an interface

or

A reference variable of the Interface type


What is the correct way of interpreting the above?

Would the below make sense?

If a class is using an interface, it must:

  • (1) inherit the properties of the interface

  • (2) provide implementation for all methods that the interface exposes

  • (3) ???

  • (4) all of the above

Jeroen Vannevel

(2) provide implementation for all methods that the interface exposes

No. Abstract classes can implement an interface without providing an implementation (they still have to declare the methods defined in the interface, but they don't have to provide a body).

I wouldn't know how to interpret number 3 either though. When looking trough the link you have provided it's just a matter of badly worded questions. I'm still trying to figure out what this means:

  1. What is the output of the code public class B : A { }
    • Errors
    • It defines a class that inherits the public methods of A only.
    • It defines a class that inherits all the methods of A but the private members cannot be accessed.
    • b and c

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Using interface to export class from dll

From Dev

Interface's implementations MUST implement its inner class builder interface. How to do it?

From Dev

Member variable which must extend class A and implement some interface

From Dev

using base class in interface

From Dev

Can I have a class field that is the Class<?> of a type that must extend another class and an interface?

From Dev

TypeScript: Reference interface in class when using AMD

From Dev

using reflection to get properties of class inheriting an interface

From Dev

Anonymous inner class using an interface in Java

From Dev

Mocking a class with an explicitly implemented interface using Foq

From Dev

ColdFusion ~ Class must not be an interface (OSX only)

From Dev

Using Interface to make a Class Trait-compatible

From Dev

Kotlin: Interface whereby the implementor must be a data class?

From Dev

Must I define both the forward declaration and the interface of a class in the same section?

From Dev

Why I must use `@RequestParam` annotation on implementation class instead of interface class only?

From Dev

Using a class that implements an interface

From Dev

Using an interface class as member type in another class

From Dev

Design problems of using abstract class with an interface

From Dev

Using interface methods of enum in method accepting class

From Dev

Must a class adhere to the documented contract of an interface to be said to implement that interface

From Dev

Using : on a class and interface

From Dev

If a class is using an interface, it must

From Dev

Member variable which must extend class A and implement some interface

From Dev

Implementing an interface through a form class using an event

From Dev

How to implement an interface using class member?

From Dev

Using WCF to Communicate Interface and Customer Class

From Dev

Using a method declared in an interface, but not class

From Dev

Declaration of class must be compatible with interface

From Dev

Specify that a Class argument must implement a particular interface

From Dev

Using Interface and Abstract class

Related Related

  1. 1

    Using interface to export class from dll

  2. 2

    Interface's implementations MUST implement its inner class builder interface. How to do it?

  3. 3

    Member variable which must extend class A and implement some interface

  4. 4

    using base class in interface

  5. 5

    Can I have a class field that is the Class<?> of a type that must extend another class and an interface?

  6. 6

    TypeScript: Reference interface in class when using AMD

  7. 7

    using reflection to get properties of class inheriting an interface

  8. 8

    Anonymous inner class using an interface in Java

  9. 9

    Mocking a class with an explicitly implemented interface using Foq

  10. 10

    ColdFusion ~ Class must not be an interface (OSX only)

  11. 11

    Using Interface to make a Class Trait-compatible

  12. 12

    Kotlin: Interface whereby the implementor must be a data class?

  13. 13

    Must I define both the forward declaration and the interface of a class in the same section?

  14. 14

    Why I must use `@RequestParam` annotation on implementation class instead of interface class only?

  15. 15

    Using a class that implements an interface

  16. 16

    Using an interface class as member type in another class

  17. 17

    Design problems of using abstract class with an interface

  18. 18

    Using interface methods of enum in method accepting class

  19. 19

    Must a class adhere to the documented contract of an interface to be said to implement that interface

  20. 20

    Using : on a class and interface

  21. 21

    If a class is using an interface, it must

  22. 22

    Member variable which must extend class A and implement some interface

  23. 23

    Implementing an interface through a form class using an event

  24. 24

    How to implement an interface using class member?

  25. 25

    Using WCF to Communicate Interface and Customer Class

  26. 26

    Using a method declared in an interface, but not class

  27. 27

    Declaration of class must be compatible with interface

  28. 28

    Specify that a Class argument must implement a particular interface

  29. 29

    Using Interface and Abstract class

HotTag

Archive