Abstract class vs Interface - Class, Objects and Interface
Q. Abstract class vs Interface- Published on 19 Oct 15a. A class may inherit only one abstract class but may inherit several interfaces.
b. An abstract class can provide complete and default code but an interface has no code
c. both a and b
d. none
ANSWER: both a and b
Abstract class and interface are generally confused to be the same but they are actually not the same. An abstract class cannot have its own instance but can have functions declared and defined inside it( normal functions). Abstract methods(functions) can only be declared inside an abstract class so in order to complete the functionality we need a subclass where the abstract functions can be defined(implemented). The functions which are only declared inside abstract class and not defined i.e. having incomplete functionality are written with keyword abstract and if an abstract class has only incomplete functions within then it is same as an Interface. Interface is not a class but an entity and it just has definition of functions with no implement ion. It is basically created to be overridden by implemented classes.