Capgemini Engineering interview question

What is the difference between interface and abstract class?

Interview Answers

Anonymous

24 Apr 2019

In Java, an abstract class are those declared as such (modified as abstract). It can contain implemented methods as well as abstract ones that should be implemented by concrete descending classes, as methods methods declared in interfaces. If an abstract class only has abstract methods it can be wrongly seen as equivalent of an interface but from an architectural point of view they are distinct since a class can only have one parent (abstract) class but, can implement multiple interfaces. Abstract classes have the advantage of being able of having methods with different visibility modifiers, such as private or protected, which aren't available to interfaces that can only declare public ones. From Java 8 interfaces can bring default and static implementations of methods and declaration of constants. Both, abstract classes and interfaces can receive anonymous implementations that would allow them to be instantiated.

2

Anonymous

15 Nov 2016

A class containing atleast one pure virtual functions is known as Abstract Class. We cannot instantiate an Abstract class. When all the functions of an abstract class are pure virtual functions, than that class is known as interface.

1