Why do I get an error instantiating an interface?

后端 未结 6 1077
生来不讨喜
生来不讨喜 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条回答
  •  半阙折子戏
    2020-12-08 06:54

    IUser is the interface, you can't instantiate the interface.

    You need to instantiate the concrete class that implements the interface.

    IUser user = new User();
    

    or

    User user = new User();
    

提交回复
热议问题