Difference between abstract class with all method abstract and interface?

后端 未结 7 1793
感动是毒
感动是毒 2020-12-29 14:05

I had an interview where interviewer asked me first what is the difference between abstract class with all the methods abstract and an interface.

I replied that if

7条回答
  •  执笔经年
    2020-12-29 14:15

    For the first situation i'd chose interface over abstract class with all methods abstract as having interface leaves me with option in future for my implementing class to extend some other (abstract) class.

    For second scenario, if you really don't want your concrete class to extend any other class and also want to "implement" contract, you can have abstract class with all methods abstract.

提交回复
热议问题