Java Basics - OO Flashcards
1
Q
Multiple inheritance of type:
Multiple inheritance of state:
A
- Multiple inheritance of type includes the ability to implement multiple interfaces and/or ability to extend from multiple classes.
- Multiple inheritance of state includes the ability to inherit instance fields from multiple classes
Interfaces, classes, and enums are all "types". Java allows a class to implement multiple interfaces. In this way, Java supports multiple inheritance of types. "State", on the other hand, is represented by instance fields. Only a class can have instance fields and therefore, only a class can have a state. (Fields defined in an interface are always implicitly static, even if you don't specify the keyword static explicitly. Therefore, an interface does not have any state.) Since a class is allowed to extend only from one class at the most, it can inherit only one state. Thus, Java does not support multiple inheritance of state.