You are on page 1of 2

Name:

Date:
Section:

Quiz: Access Modifiers

1. Class members that should be public are


I. Constructors

II. Instance Variables

III. Accessors/Mutators

IV. Methods the class uses for itself, but the user does not need

V. Methods the user needs to manipulate the objects of the class

A. I, II, IV
B. I, II, III
C. I, III, V
D. I, II, III, V

2. What is the difference between a getter method and an accessor method?

A. A getter method allows you to get the value of a field while an accessor method sets the value of the field.
B. A getter method allows you to get the value of a field while an accessor method is not often used in Java.
C. A getter method gets the name of the class while an accessor method gets the value of the field.
D. There is no difference. They refer to the same idea.

3. What is the scope of private methods and private instance variables?

A. Any class using an object of the declaring class


B. The declaring class
C. The main method

D. Only the private methods of the declaring class

4. Accessors and mutators are used to

A. Allow private data to be accessed outside of the class and be safely modified.
B. Allow users to access and modify any of the class’s data in any way they wish.
C. Prevent users from manipulating private data.
D. Allow public data to be accessed and safely modified.

5. Classes’ access specifier is generally set to

A. private to prevent any user from accessing and modifying any instance variables.
B. private so that only certain users can create objects of the class.
C. public so that all data and methods are accessible by any user.
D. public so that any user can create and use objects of the class.

You might also like