non-static, it cannot be accessed in the main method without creating an object. (D) is incorrect, since it is permissible
to create an instance of the class within the class. The best choice is (C).
#
31. To prevent a class from being instantiated,
a. don’t use any modifiers on the constructor.
b. use the public modifier on the constructor.
c. use the private modifier on the constructor.
d. use the static modifier on the constructor.
#
Section 9.9 Data Field Encapsulation
37. Which is the advantage of encapsulation?
a. Only public methods are needed.
b. Making the class final causes no consequential changes to other code.
c. It enables changes to the implementation without changing a class’s contract and causes no consequential changes
to other code.
d. It enables changes to a class’s contract without changing the implementation and causes no consequential changes
to other code.
#
35. Which of the following statements are true?
a. Use the private modifier to encapsulate data fields.
b. Encapsulating data fields makes the program easy to maintain.
c. Encapsulating data fields makes the program short.
d. Encapsulating data fields helps prevent programming errors.
#
36. Suppose you wish to provide an accessor method for a boolean property finished, what should the signature of this
method?
a. public void getFinished()
b. public boolean getFinished()
c. public boolean isFinished()
d. public void isFinished()
#
65. Encapsulation means .
a. that data fields should be declared private
b. that a class can extend another class
c. that a variable of supertype can refer to a subtype object
d. that a class can contain another class
#
Section 9.10 Passing Objects to Methods
39. What is the value of myCount.count displayed?
public class Test {
public static void main(String[] args) {
Count myCount = new Count();