PRITE 2024 HW 4 Exam with 100%
Correct Answers!!
1. What does it mean for a local variable to shadow a field? - โโThe
local value hide the value of the instance field it is named after.
2. What is the difference between a constructor, accessor (getter), and
mutator (setter)? - โโA constructor performs operation at the time
the object is created (it has no return type and is not given any
instructions is created as default). It initializes fields. Accessor all you to
retrieve the data from the field it is held in(has a return type). A
mutator allows you to manipulate the data is the instance fields (void
return type).
3. What is the difference between a class and an instance of the class? -
โโA class is a blueprint for the instances of the class. The class would
be a cookiecutter and the cookies would the instance of the class
(object).
4. Is it a good idea to make fields private? Why or why not? - โโIt
makes the access to the data in the field limited. The only way a person
can get the data is by utilizing one of the methods (protect the data).
5. If a class has a private field, what has access to the field? - โโThe
methods in the class.