Why do I get an error instantiating an interface?

后端 未结 6 1080
生来不讨喜
生来不讨喜 2020-12-08 06:22

I have a class and an interface, and when I try to instantiate the interface, I get an error:

Cannot create an instance of the abstract class or inter

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 07:03

    You can't instantiate interfaces or abstract classes.

    That's because it wouldn't have any logic to it.

    Interfaces provide a contract of the methods that should be in a class, without implementation. (So there's no actual logic in the interface).

    Abstract classes provide basic logic of a class, but are not fully functional (not everything is implemented). So again, you won't be able to do anything with it.

提交回复
热议问题