从
Java How to Program有关抽象类:
Because they’re used only as superclasses in inheritance hierarchies,
we refer to them as abstract superclasses. These classes cannot be
used to instantiate objects, because abstract classes are incomplete.
Subclasses must declare the “missing pieces” to become “concrete” classes,
from which you can instantiate objects. Otherwise, these subclasses, too,
will be abstract.
回答你的问题“使用interfacs的原因是什么?”:
An abstract class’s purpose is to provide an appropriate superclass
from which other classes can inherit and thus share a common design.
与接口相反:
An interface describes a set of methods that can be called on an
object, but does not provide concrete implementations for all the
methods… Once a class implements an interface, all objects of that class have
an is-a relationship with the interface type, and all objects of the
class are guaranteed to provide the functionality described by the
interface. This is true of all subclasses of that class as well.
所以,为了回答你的问题“我想知道什么时候我应该使用接口”,我想你应该使用接口,当你想要一个完整的实现和使用抽象类,当你想要的部分为你的设计(为了可重用性)