what is the advantage of interface over abstract classes?

前端 未结 9 1898
野的像风
野的像风 2021-02-01 05:48

In Java, abstract classes give the ability to define both concrete and abstract methods whereas interfaces only give the ability to implement abstract methods. I believe overrid

9条回答
  •  有刺的猬
    2021-02-01 06:25

    -Method without any implementation is abstract method,whenever a class contains one or more abstract method,then it must be declared as a abstract class

    -Interface is fully abstract which cannot have constructor,instance and static blocks,and it contains only two types of members 1.public abstract method 2.public-static-final variable

    *Both cannot be instantiated but reference can be created.

    *Which one suits better depends on the application -Interfaces are useful because Java classes will not support multiple inheritance but interfaces do.

    -Abstract classes are useful when you need concrete behavior from the base class.

提交回复
热议问题