What is inheritance in object-oriented programming?
Inheritance lets one class acquire selected state and behavior from another class, while also allowing the new class to add or replace members.
Study 4 Inheritance and Class Hierarchies with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What is inheritance in object-oriented programming?
Inheritance lets one class acquire selected state and behavior from another class, while also allowing the new class to add or replace members.
What are the two classes in an inheritance relationship called?
The existing class is the superclass, base class, or parent class; the new class is the subclass, derived class, or child class.
What does an “is-a” relationship mean?
An is-a relationship means the subclass represents a specialized form of the superclass, such as a Dog being an Animal.
How can inheritance form a class hierarchy?
A subclass can normally have one direct superclass, while a superclass can have many subclasses. Inheritance can also form a chain such as Animal → Mammal → Dog.
Are constructors generally inherited?
Constructors are generally not inherited, although a subclass can invoke a superclass constructor.
How does inheritance support reuse through extension?
A subclass reuses common superclass code and adds features that distinguish the specialized type, reducing duplication and centralizing shared behavior.
What is the purpose of an abstract superclass?
An abstract superclass represents a meaningful general concept, provides shared implementation, and may require subclasses to implement essential operations.
What is method overriding?
Overriding occurs when a subclass supplies a new implementation with the same method signature as an inherited overridable method.
What does Java’s @Override annotation provide?
In Java, @Override documents the programmer’s intent and lets the compiler detect mistakes such as an incorrectly spelled method name.
How can an override reuse the superclass implementation?
A subclass can call the superclass implementation with super in Java or base in C# before adding its own behavior.
What does polymorphism enable?
Polymorphism lets code use a superclass reference while the runtime selects the overridden method belonging to the object’s actual subclass.
When is inheritance a good design choice?
Use inheritance when the subclass is genuinely specialized, the superclass behavior fits every subclass, and subclasses can honor its expectations.