Inheritance Flashcards
What is subtyping?
When we establish an ‘is-a’ relationship between one type and another type.
What are parent classes know is in C++?
base or virtual classes and derived classes.
How do you type extend Animal class?
: public Animal
What happens if the specifier for the class extension is public?
base class public and protected members keep the same access.
What happens if the specifier for the class extension is protected?
base class public and protected members are protected.
What happens if the specifier for the class extension is private?
Base class public and protected members are private.
What is a protected member variable?
Restricts access to certain class members to the class itself and its derived classes. Allowing access to derived classes but not external.
What is polymorphism?
Same function names with different functionality due to parameters and typing.
How is polymorphism achieved in C++?
Virtual functions/classes
What are virtual functions/classes?
Mechanisms to declare a function in a base class and for that function with the same name and type to be implemented in a derived class.
What can derived classes do to public/protected code in the base class?
Override it.
How do we determine which specific function for virtual functions to use?
Based on the type of object used at runtime (runtime polymorphism)
What is multiple inheritance?
When a derived class inherits from two+ base classes.
What are common ancestors?
Classes that inherit the same class through multiple inheritance.
What is the diamond problem?
The ambiguity that arises when a class inherits from classes that have a common ancestor, leading to potential conflicts.