1/38
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What is inheritance in OOP?
A way to define a class in terms of another class.
Why is inheritance useful?
It helps organization, maintenance, code reuse, and implementation speed.
What is a base class?
The existing class being inherited from.
What is a derived class?
The new class that inherits from a base class.
What is another name for base class?
Superclass.
What is another name for derived class?
Subclass.
How do you declare a derived class in C++?
class Derived : access_specifier Base { … };
What access specifiers can be used in inheritance?
public, protected, private
What is the default inheritance access if omitted in a class derivation list?
private
Can a derived class inherit from more than one base class in C++?
Yes.
What is that called?
Multiple inheritance.
How do you write multiple inheritance?
By listing multiple base classes separated by commas after the colon.
What members can members of the same class access?
public, protected, and private
What members can members of a derived class access?
public and protected, but not private
What members can non-members access?
public only
What happens in public inheritance?
Inherited members keep the same access levels they had in the base class.
What happens in protected inheritance?
Base-class public members become protected in the derived class.
What happens in private inheritance?
Inherited members become private in the derived class.
Which inheritance style does the slide deck generally recommend for most use cases?
public inheritance
If a base class member is protected, can a derived class access it directly?
Yes.
If a base class member is private, can a derived class access it directly?
No.
If a base class member is private, how should a derived class usually work with it?
Through public/protected methods such as setters/getters.
In inheritance, which constructor runs first: base or derived?
Base constructor first.
In inheritance, which destructor runs last: base or derived?
Base destructor last.
If you do not explicitly specify which base constructor to call, which one is used?
The default constructor.
How do you explicitly choose a base constructor from a derived constructor?
With an initializer list, like Child(int x) : Parent(x) { }
What is a friend of a class?
A function or class given access to the class’s private/protected members.
Is friendship reciprocal by default?
No.
Is friendship transitive by default?
No.
What is a friend function?
A non-member function declared with friend that can access private/protected members.
Is a friend function actually a member of the class?
No.
What is a friend class?
A class whose members can access another class’s private/protected members.
Why might a forward declaration be needed with friend classes?
To deal with circular dependencies between classes.