Pergunta de entrevista da empresa Safe Software

Difference between abstract and interface

Resposta da entrevista

Sigiloso

10 de dez. de 2017

An INTERFACE is a treaty. or promise made on behalf of a (or many) classes. It promises, " I will respond to the following function calls with the given signatures". However, the interface definition itself contains no implementation nor data fields itself. Thus an INTERFACE can not be instantiated (no new _____ () calls on the interface) since there is no code behind the interface itself. An ABSTRACT class, on the other hand, also provides promises, but it (may) contain data definitions or even default implementations of some of the methods. However, some other methods, themselves declared abstract, may be missing an implementation. Thus, an Abstract class also may not be instantiated directly. rather one of it's subclasses must be instantiated in order that a complete implementation be had.