Inheritance Flashcards

1
Q

What is subtyping?

A

When we establish an ‘is-a’ relationship between one type and another type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are parent classes know is in C++?

A

base or virtual classes and derived classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you type extend Animal class?

A

: public Animal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What happens if the specifier for the class extension is public?

A

base class public and protected members keep the same access.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What happens if the specifier for the class extension is protected?

A

base class public and protected members are protected.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What happens if the specifier for the class extension is private?

A

Base class public and protected members are private.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a protected member variable?

A

Restricts access to certain class members to the class itself and its derived classes. Allowing access to derived classes but not external.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is polymorphism?

A

Same function names with different functionality due to parameters and typing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How is polymorphism achieved in C++?

A

Virtual functions/classes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are virtual functions/classes?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What can derived classes do to public/protected code in the base class?

A

Override it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do we determine which specific function for virtual functions to use?

A

Based on the type of object used at runtime (runtime polymorphism)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is multiple inheritance?

A

When a derived class inherits from two+ base classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are common ancestors?

A

Classes that inherit the same class through multiple inheritance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the diamond problem?

A

The ambiguity that arises when a class inherits from classes that have a common ancestor, leading to potential conflicts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do we solve the diamond problem?

A

Virtual keyword for classes

17
Q

What are virtual classes?

A

Using the virtual keyword, prevents multiple copies of the base class, resolving the ambiguity caused by ancestors and multiple inheritance. Allows a derived class to inherit from a common base class only once.

18
Q

What is a pure virtual function and what does it to do a base class??

A

A pure virtual function is a function that requires an implementation by the derived class, meaning the base class is abstract and cannot be instantiated.

19
Q

What is an abstract class?

A

A class that contains at least one pure virtual function and cannot be instantiated directly, serving as a blueprint for derived classes to implement specific functionality.

20
Q

What is the syntax for a pure virtual function?

A

Use the virtual key word and have the function = 0 in the function prototype, e.g.:

virtual void doSomething() = 0;