C++ Getters and Setters Quiz

C++ Getters and Setters Quiz

Assessment

Interactive Video

Computers

9th - 10th Grade

Hard

Created by

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'

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?