

C++ Getters and Setters Quiz
Interactive Video
•
Computers
•
9th - 10th Grade
•
Practice Problem
•
Hard
Jennifer Brown
FREE Resource
10 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the primary purpose of a getter in C++?
To delete private variables
To access private variables
To create new private variables
To modify private variables
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Why do we need getters and setters in a class?
To provide controlled access to private variables
To increase the size of the class
To decrease the complexity of the class
To make all variables public
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
In the class example, what was the initial size of the shirt?
Extra Large
Small
Large
Medium
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the return type of the getter function implemented in the video?
bool
int
void
string
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the purpose of the setter function in the class?
To access private variables
To modify private variables with validation
To create new private variables
To delete private variables
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of the following is NOT a valid size for the shirt in the setter function?
XS
XXL
M
L
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What happens if you try to set an invalid size using the setter function?
The size is set to 'null'
The size is set to 'unknown'
The program crashes
The size is set to 'default'
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?