What is the difference between an interface and abstract class?

前端 未结 30 1866
情歌与酒
情歌与酒 2020-11-21 11:51

What exactly is the difference between an interface and abstract class?

30条回答
  •  太阳男子
    2020-11-21 12:16

    We have various structural/syntactical difference between interface and abstract class. Some more differences are

    [1] Scenario based difference:

    Abstract classes are used in scenarios when we want to restrict the user to create object of parent class AND we believe there will be more abstract methods will be added in future.

    Interface has to be used when we are sure there can be no more abstract method left to be provided. Then only an interface is published.

    [2] Conceptual difference:

    "Do we need to provide more abstract methods in future" if YES make it abstract class and if NO make it Interface.

    (Most appropriate and valid till java 1.7)

提交回复
热议问题