Chapter 6 Book Quiz Flashcards
This is a collection of programming statements that specify the fields and methods that a particular type of object may have.
a. class
b. method
c. parameter
d. instance
a. class
Explanation: A class defines the structure of objects, specifying their fields (data) and methods (actions). It acts as a blueprint for creating objects.
A class is analogous to a(n):
a. house
b. blueprint
c. drafting table
d. architect
b. blueprint
Explanation: A class acts like a blueprint, detailing how an object should look and behave, just like a blueprint outlines the construction of a house.
An object is a(n):
a. blueprint
b. primitive data type
c. variable
d. instance of a class
d. instance of a class
Explanation: Objects are specific instances created from a class. They occupy memory and hold data and behavior defined by the class.
This is a class member that holds data:
a. method
b. instance
c. field
d. constructor
c. field
Explanation: Fields are variables defined inside a class that hold data for each object created from that class.
This key word causes an object to be created in memory:
a. create
b. new
c. object
d. construct
b. new
Explanation: The new keyword allocates memory for an object and calls its constructor.
This is a method that gets a value from a class’s field, but does not change it:
a. accessor
b. constructor
c. void
d. mutator
a. accessor
Explanation: Accessor methods, often called “getters,” retrieve the value of a field without modifying it.
This is a method that stores a value in a field or in some other way changes the value of a field:
a. accessor
b. constructor
c. void
d. mutator
d. mutator
Explanation: Mutator methods, often called “setters,” change the value of fields.
When the value of an item is dependent on other data, and that item is not updated when the other data is changed, what has the value become?
a. bitter
b. stale
c. asynchronous
d. moldy
b. stale
Explanation: Stale data occurs when dependent data changes but the computed value is not recalculated, leading to outdated information.
This is a method that is automatically called when an instance of a class is created:
a. accessor
b. constructor
c. void
d. mutator
b. constructor
Explanation: Constructors are special methods invoked during object creation to initialize the object.
When a local variable has the same name as a field, the local variable’s name does this to the field’s name:
a. shadows
b. complements
c. deletes
d. merges with
a. shadows
Explanation: Shadowing occurs when a local variable with the same name as a field hides the field within the scope of the method.
This is automatically provided for a class if you do not write one yourself:
a. accessor method
b. default instance
c. default constructor
d. variable declaration
c. default constructor
Explanation: Java provides a default no-argument constructor if no other constructor is explicitly defined in the class.
Two or more methods in a class may have the same name, as long as this is different:
a. their return values
b. their access specifier
c. their parameter lists
d. their memory address
c. their parameter lists
Explanation: Method overloading allows multiple methods to share the same name if they have different parameter lists.
The process of matching a method call with the correct method is known as:
a. matching
b. binding
c. linking
d. connecting
b. binding
Explanation: Binding is the process of associating a method call with its corresponding method using the method signature.
A class’s responsibilities are:
a. the objects created from the class
b. things the class knows
c. actions the class performs
d. both b and c
d. both b and c
Explanation: A class’s responsibilities include storing data (fields) and performing actions (methods).
TRUE OR FALSE: The new operator creates an instance of a class.
TRUE
Explanation: The new operator is used to instantiate an object, allocating memory and invoking its constructor.