QUESTIONS CORRECT RESPONSES
◉ Consider the following code snippet:
public class Coin
{
...
public void setCoinName(String name)
{. . . }
public String getCoinName()
{. . . }
public String getCoinValue()
{. . . }
}
Assuming that the names of the methods reflect their action, which
of the following statements about this class is correct?
a) setCoinName is an accessor method.
b) setCoinName is a mutator method.
c) getCoinName is a mutator method.
,d) getCoinValue is a mutator method. Answer: b
◉ A method in a class that returns information about an object but
does not change the object is called a/an ____ method.
a) mutator
b) accessor
c) void
d) constructor Answer: b
◉ A method in a class that modifies information about an object is
called a/an ____ method.
a) mutator
b) accessor
c) void
d) constructor Answer: a
◉ 32) Which of the following is an accessor method of the
CashRegister class used in the textbook?
a) getTotal
,b) addItem
c) clear
d) The CashRegister class does not have any accessor methods.
Answer: a
◉ Which of the following is a mutator method of the CashRegister
class used in the textbook?
a) getTotal
b) getCount
c) clear
d) The CashRegister class does not have any mutator methods.
Answer: c
◉ Which type of method modifies the object on which it is invoked?
a) Constructor method.
b) Static method.
c) Accessor method.
d) Mutator method. Answer: d
◉ The utility that formats program comments into a set of
documents that you can view in a Web browser is called ____.
, a) javadoc
b) javac
c) javad
d) java Answer: a
◉ You should declare all instance variables as ___.
a) protected
b) class
c) public
d) private Answer: d
◉ Private instance variables ___.
a) can only be accessed by methods of a different class
b) can only be accessed by methods of the same class
c) cannot be accessed by methods of the same class
d) can only be accessed by the constructor of the class Answer: b