9.3. Object-Oriented Programming Problems
Problems you are presented relating to object-oriented programming are likely to focus on the concepts of object orientation, particularly on issues relevant to the languages the company is using in its coding.
9.3.1. Interfaces and Abstract Classes
NOTE
Explain the difference between an interface and an abstract class in object-oriented programming.
The specific answer to this depends, of course, on which language you're developing with, but start the answer by giving some general definitions:
An interface declares a set of related methods, outside of any class.
An abstract class is an incomplete class definition that declares but does not define all of its methods.
Conceptually, then, an interface defines an application programming interface (API) that is independent of any class hierarchy. In fact, interfaces can be used in non-OO programming models, such as component-based models like COM and CORBA. However, you're focusing on the use of interfaces in an object-oriented context, where they are useful in their own right. Interfaces are the ultimate encapsulators, because they hide all the details of the classes that implement their methods from the user of the interface. They're particularly important — almost necessary, in fact — in languages that only support single inheritance (classes can only inherit from one base class). A class that exposes its members via an interface is said to implement the interface.
Unlike an interface, ...
Get Programming Interviews Exposed: Secrets to Landing Your Next Job, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.