Ch8/1

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

49) Which statement calls a constructor with no construction parameters? a) Circle c = new Circle(); b) Circle c = new Circle; c) Circle c = Circle() d) A call to a constructor must have construction parameters.

a) Circle c = new Circle();

29) 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.

b) setCoinName is a mutator method.

1) Given the following class definition, which of the following are considered part of the class's public interface? public class CashRegister { public static final double DIME_VALUE = 0.1; private static int objectCounter; public void updateDimes(int dimes) {. . .} private boolean updateCounter(int counter) {. . .} } a) objectCounter and updateCounter b) DIME_VALUE and objectCounter c) DIME_VALUE and updateDimes d) updateDimes and updateCounter

c) DIME_VALUE and updateDimes

11) Which of the following statements about encapsulation is correct? a) Encapsulation enables changes to the public interface without affecting users of the class. b) Encapsulation prohibits changes to the implementation details to ensure that users of the class will not be affected. c) Encapsulation enables changes to the implementation details without affecting users of the class. d) Encapsulation provides an easier means of transporting class information.

c) Encapsulation enables changes to the implementation details without affecting users of the class.

26) Which of the following statements about a class is correct? a) A class should not have private instance variables. b) Private instance variables are the interface to the class. c) Private instance variables hide the implementation of a class from the class user. d) Private instance variables should rarely be used in classes.

c) Private instance variables hide the implementation of a class from the class user

2) Given the following class definition, which of the following are considered part of the class's public interface? public class Motorcycle { public static final int WHEEL_COUNT = 2; private int rpmRating; public void updatePrice(double increase) {...} private String designCode() {...} } a) rpmRating and designCode b) WHEEL_COUNT and designCode c) WHEEL_COUNT and updatePrice d) updatePrice and designCode

c) WHEEL_COUNT and updatePrice

33) 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.

c) clear

42) Input to a method enclosed in parentheses after the method name is known as ____. a) implicit parameters b) interfaces c) explicit parameters d) return values

c) explicit parameters

43) The object on which a method is invoked is called the ____. a) interface b) procedure c) implicit parameter d) explicit parameter

c) implicit parameter

16) When an object is created from a class, the object is called a/an ____ of the class. a) child b) constructor c) instance d) subclass

c) instance

15) The ____ operator is used to construct an object from a class. a) add b) create c) new d) construct

c) new

46) Which of the following statements about classes is correct? a) All instance variables and most instance methods should be declared as public. b) All instance variables and most instance methods should be declared as private. c) All instance variables should be declared as public and most instance methods should be declared as private. d) All instance variables should be declared as private and most instance methods should be declared as public.

d) All instance variables should be declared as private and most instance methods should be declared as public.

47) Which of the following statements about instance methods is correct? a) An instance method should always be declared as public. b) An instance method should always be declared as private. c) An instance method should be declared as public only if it is a helper method. d) An instance method should be declared as private only if it is a helper method.

d) An instance method should be declared as private only if it is a helper method.

34) Which type of method modifies the object on which it is invoked? a) Constructor method. b) Static method. c) Accessor method. d) Mutator method.

d) Mutator method.

10) Which of the following statements about encapsulation is correct? a) To use encapsulation, you must provide a set of private methods in the class. b) To use encapsulation, the class must contain only public methods in the class. c) To use encapsulation, the implementation details must be public. d) To use encapsulation, you must provide a set of public methods in the class and hide the implementation details.

d) To use encapsulation, you must provide a set of public methods in the class and hide the implementation details.

41) Which of the following lists the correct order of items in an instance method declaration? a) the return type, the name of the method, and a list of the parameters (if any) b) modifiers, the type of the instance variable, and the name of the instance variable c) the type of the instance variable, modifiers, and a list of the parameters (if any) d) modifiers, a return type, a method name, and a list of the parameters (if any)

d) modifiers, a return type, a method name, and a list of the parameters (if any)

36) You should declare all instance variables as ___. a) protected b) class c) public d) private

d) private

39) Which of the following declares a rpmRating instance variable for a Motor class that stores an integer value? a) private integer rpmRating; b) private int rpmRating; c) public integer rpmRating; d) public int rpmRating;

b) private int rpmRating;

38) Which of the following declares a sideLength instance variable for a Square class that stores an integer value? a) private integer sideLength; b) private int sideLength; c) public integer sideLength; d) public int sideLength;

b) private int sideLength;

27) Consider the following code snippet: public class Vehicle { . . . public void setVehicleAttributes(String attributes) {. . . } public String getVehicleAtrributes() {. . . } public String getModelName() {. . . } } Assuming that the names of the methods reflect their action, which of the following statements about this class is correct? a) setVehicleAttributes is an accessor method. b) setVehicleAttributes is a mutator method. c) getVehicleAttributes is a mutator method. d) getModelName is a mutator method.

b) setVehicleAttributes is a mutator method.

21) Which of the following statements is true regarding classes? a) Each object of a class has a separate copy of each instance variable. b) All objects created from a class share a single set of instance variables. c) Private instance variables can be accessed by any user of the object. d) Public instance variables can be accessed only by the object itself.

a) Each object of a class has a separate copy of each instance variable.

23) Consider the following code snippet: public class Coin { private String coinName; public String getCoinValue() { . . . } } Which of the following statements is correct? a) The getCoinValue method can be accessed by any user of a Coin object. b) The getCoinValue method can be accessed only by methods of the Coin class. c) The getCoinValue method can be accessed only by methods of another class. d) The getCoinValue method cannot be accessed at all.

a) The getCoinValue method can be accessed by any user of a Coin object.

25) Consider the following code snippet: public class Employee { private String empName; public String getEmpName() { . . . } } Which of the following statements is correct? a) The getEmpName method can be accessed by any user of an Employee object. b) The getEmpName method can be accessed only by methods of the Employee class. c) The getEmpName method can be accessed only by methods of another class. d) The getEmpName method cannot be accessed at all.

a) The getEmpName method can be accessed by any user of an Employee object.

12) Which of the following statements about classes is correct? a) When programmers work with an object of a class, they do not need to know how the object stores its data or how its methods are implemented. b) When programmers work with an object of a class, they must understand how the object stores its data and how its methods are implemented. c) When programmers work with an object of a class, they must understand only how the object stores its data. b) When programmers work with an object of a class, they must understand only how the object's methods are implemented.

a) When programmers work with an object of a class, they do not need to know how the object stores its data or how its methods are implemented.

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

a) getTotal

8) The public constructors and methods of a class form the public _____ of the class. a) interface b) initialization c) implementation d) encapsulation

a) interface

35) 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

a) javadoc

31) A method in a class that modifies information about an object is called a/an ____ method. a) mutator b) accessor c) void d) constructor

a) mutator

3) Given the following class definition, which of the following are NOT considered part of the class's public interface? public class CashRegister { public static final double DIME_VALUE = 0.1; private static int objectCounter; public void updateDimes(int dimes) {...} private boolean updateCounter(int counter) {...} } a) objectCounter and updateCounter b) DIME_VALUE and objectCounter c) DIME_VALUE and updateDimes d) updateDimes and updateCounter

a) objectCounter and updateCounter

4) Given the following class definition, which of the following are NOT considered part of the class's public interface? public class Motorcycle { public static final int WHEEL_COUNT = 2; private int rpmRating; public void updatePrice(double increase) {...} private String designCode() {...} } a) rpmRating and designCode b) WHEEL_COUNT and designCode c) WHEEL_COUNT and updatePrice d) updatePrice and designCode

a) rpmRating and designCode

28) Consider the following code snippet: public class Vehicle { . . . public void setVehicleAttributes(String attributes) {. . . } public String getVehicleAtrributes() {. . . } public String getModelName() {. . . } } Assuming that the names of the methods reflect their action, which of the following statements about these instance methods is NOT correct? a) setVehicleAttributes is an accessor method. b) setVehicleAttributes is a mutator method. c) getVehicleAttributes is an accessor method. d) getModelName is an accessor method

a) setVehicleAttributes is an accessor method.

20) Which of the following is NOT part of the declaration of an instance variable? a) the return type b) a modifier specifying the level of access c) the data type d) the name

a) the return type

48) Which of the following statements about constructors is NOT correct? a) A constructor must have the same name as the class name. b) A call to a constructor must always have construction parameters. c) A constructor initializes the instance variables of an object. d) A class can have more than one constructor

b) A call to a constructor must always have construction parameters

9) Which of the following statements about classes is correct? a) A class is an object that can be manipulated by a program. b) A class describes a set of objects with the same behavior. c) Class is another name for a method. d) A class can contain only methods

b) A class describes a set of objects with the same behavior.

5) Which of the following are considered members of a class? a) Private instance variables and methods. b) All instance variables and methods. c) Non-static instance variables and methods. d) Public instance variables and methods.

b) All instance variables and methods.

6) Which of the following statements about objects is correct? a) An object defines only the methods for a class. b) Every object has its own set of data and a set of methods to manipulate the data. c) An object is a sequence of instructions that performs a task. d) All entities, even numbers, are objects.

b) Every object has its own set of data and a set of methods to manipulate the data.

40) Which statement about instance variables is correct? a) Instance variables must be declared within a method. b) Instance variables must be declared inside the class, but outside any method. c) Instance variables may be declared inside the class, or inside a method. d) Instance variables must be declared outside the class

b) Instance variables must be declared inside the class, but outside any method

13) You have created a Motorcycle class which has a constructor with no parameters. Which of the following statements will construct an object of this class? a) Motorcycle myBike; b) Motorcycle myBike = new Motorcycle(); c) myBike.new(Motorcycle); d) Motorcycle.new(myBike);

b) Motorcycle myBike = new Motorcycle();

14) You have created a Rocket class which has a constructor with no parameters. Which of the following statements will construct an object of this class? a) Rocket myRocket; b) Rocket myRocket = new Rocket(); c) myRocket.new(Rocket); d) Rocket.new(myRocket);

b) Rocket myRocket = new Rocket();

22) Consider the following code snippet: public class Coin { private String coinName; . . . } Which of the following statements is correct? a) The coinName variable can be accessed by any user of a Coin object. b) The coinName variable can be accessed only by methods of the Coin class. c) The coinName variable can be accessed only by methods of another class. d) The coinName variable cannot be accessed at all because it is private.

b) The coinName variable can be accessed only by methods of the Coin class.

24) Consider the following code snippet: public class Employee { private String empName; . . . } Which of the following statements is correct? a) The empName variable can be accessed by any user of an Employee object. b) The empName variable can be accessed only by methods of the Employee class. c) The empName variable can be accessed only by methods of another class. d) The empName variable cannot be accessed at all because it is private.

b) The empName variable can be accessed only by methods of the Employee class.

30) 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

b) accessor

19) An instance variable declaration consists of ____. a) the return type, the name of the method, and a list of the parameters (if any). b) an access specifier, the type of the instance variable, and the name of the instance variable. c) an access specifier, a list of the parameters (if any), and the body of the method. d) the type of the instance variable, an access specifier, a list of the parameters (if any), and the body of the method.

b) an access specifier, the type of the instance variable, and the name of the instance variable

37) 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

b) can only be accessed by methods of the same class

45) Consider the following code snippet: public int getCoinValue(String coinName) { . . . } Which of the following statements is correct? a) coinName is an implicit parameter. b) coinName is an explicit parameter. c) coinName is the object on which this method is invoked. d) coinName is an instance variable

b) coinName is an explicit parameter.

44) Consider the following code snippet: public int getSalary(String empNum) { . . . } Which of the following statements is correct? a) empNum is an implicit parameter. b) empNum is an explicit parameter. c) empNum is the object on which this method is invoked. d) empNum is an instance variable

b) empNum is an explicit parameter.

7) The process of hiding object data and providing methods for data access is called ____. a) documentation b) encapsulation c) implementation d) initialization

b) encapsulation

18) Each object of a class has a separate copy of each ___. a) method b) instance variable c) constructor d) class

b) instance variable

17) Data required for an object's use are stored in ____. a) local variables b) instance variables c) parameters d) methods

b) instance variables

50) A constructor is invoked when ___ to create an object. a) the class keyword is used b) the class is defined as public c) the new keyword is used d) the class is defined as private

c) the new keyword is used


Set pelajaran terkait

Chapter 7: Environmental Policy: Making Decisions and Solving Problems

View Set

Craven Chapter 9: Patient Education and Health Promotion

View Set

LinuxSystemAdminChpt2AccessingCommandLine

View Set