3. Class Creation

Accessor Methods — Quiz

Test your understanding of accessor methods with 5 practice questions.

Read the lesson first

Practice Questions

Question 1

What is the main purpose of an accessor method in a class?

Question 2

Which method name and header would most likely be an accessor method for a private instance variable named $age$?

Question 3

What is the best reason to make an instance variable private and provide an accessor method instead of making the variable public?

Question 4

Consider the class declaration $public class Book$ with a private instance variable $private String title;$. Which expression would correctly use an accessor method named $getTitle()$ on an object named $novel$?

Question 5

What does an accessor method typically return?