Chapter 11: Problem 25
How is an interface different from an abstract class, or any class?
Short Answer
Expert verified
Answer: The major differences between interfaces and abstract classes are:
1. Interfaces are a collection of abstract methods with no implementation, while abstract classes can contain both abstract and non-abstract methods.
2. A class implementing an interface must provide implementations for all its methods, while a class extending an abstract class can choose which abstract methods to override.
3. A class can implement multiple interfaces but can only inherit from one abstract class, allowing multiple inheritance with interfaces and not with abstract classes.
4. Interfaces can only contain constant variables, while abstract classes can have both constant and non-constant variables.
5. Interfaces do not have constructors, while abstract classes can have constructors used by derived classes to initialize their state.