Deck 8: Objects and Classes
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/101
Play
Full screen (f)
Deck 8: Objects and Classes
1
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.
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
2
The process of hiding object data and providing methods for data access is called ____.
A) documentation
B) encapsulation
C) implementation
D) initialization
A) documentation
B) encapsulation
C) implementation
D) initialization
B
3
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.
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
4
Data required for an object's use are stored in ____.
A) local variables
B) instance variables
C) parameters
D) methods
A) local variables
B) instance variables
C) parameters
D) methods
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
5
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
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
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
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.
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
7
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);
A) Rocket myRocket;
B) Rocket myRocket = new Rocket();
C) myRocket.new(Rocket);
D) Rocket.new(myRocket);
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
8
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
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
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
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.
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
10
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);
A) Motorcycle myBike;
B) Motorcycle myBike = new Motorcycle();
C) myBike.new(Motorcycle);
D) Motorcycle.new(myBike);
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
11
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.
B) When programmers work with an object of a class, they must understand only how the object's methods are implemented.
C) When programmers work with an object of a class, they must understand only how the object stores its data.
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.
B) When programmers work with an object of a class, they must understand only how the object's methods are implemented.
C) When programmers work with an object of a class, they must understand only how the object stores its data.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
12
Each object of a class has a separate copy of each ___.
A) method
B) instance variable
C) constructor
D) class
A) method
B) instance variable
C) constructor
D) class
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
13
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
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
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
14
The public constructors and methods of a class form the public _____ of the class.
A) interface
B) initialization
C) implementation
D) encapsulation
A) interface
B) initialization
C) implementation
D) encapsulation
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
15
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.
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
16
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
B) a modifier specifying the level of access
C) the data type
D) the name
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
17
The ____ operator is used to construct an object from a class.
A) add
B) create
C) new
D) construct
A) add
B) create
C) new
D) construct
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
18
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.
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
19
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
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
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
20
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
A) child
B) constructor
C) instance
D) subclass
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
21
Which type of method modifies the object on which it is invoked?
A) Constructor method.
B) Static method.
C) Accessor method.
D) Mutator method.
A) Constructor method.
B) Static method.
C) Accessor method.
D) Mutator method.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
22
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.
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
23
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.
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
24
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
B) javac
C) javad
D) java
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
25
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.
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
26
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
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
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
27
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
A) mutator
B) accessor
C) void
D) constructor
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
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 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.
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
29
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;
A) private integer sideLength;
B) private int sideLength;
C) public integer sideLength;
D) public int sideLength;
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
30
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
B) accessor
C) void
D) constructor
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
31
You should declare all instance variables as ___.
A) protected
B) class
C) public
D) private
A) protected
B) class
C) public
D) private
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
32
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
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
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
33
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.
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
34
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.
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
35
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.
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
36
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
B) addItem
C) clear
D) The CashRegister class does not have any accessor methods.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
37
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.
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
38
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;
A) private integer rpmRating;
B) private int rpmRating;
C) public integer rpmRating;
D) public int rpmRating;
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
39
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.
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
40
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.
A) getTotal
B) getCount
C) clear
D) The CashRegister class does not have any mutator methods.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
41
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
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
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
42
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();
B) Circle c = new Circle;
C) Circle c = Circle()
D) A call to a constructor must have construction parameters.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
43
Consider the following code snippet:
Public class Coin
{
Private String coinName;
Private int coinValue;
Public Coin()
{
}
) . .
}
Which statement reflects the action performed when the constructor to Coin is called?
A) The variable coinName will be initialized to "" and the variable coinValue will be initialized to 0.
B) The variable coinName will be initialized to "null" and the variable coinValue will be initialized to 0.
C) The variable coinName will not be initialized but the variable coinValue will be initialized to 0.
D) The variable coinName will be initialized to null and the variable coinValue will be initialized to 0.
Public class Coin
{
Private String coinName;
Private int coinValue;
Public Coin()
{
}
) . .
}
Which statement reflects the action performed when the constructor to Coin is called?
A) The variable coinName will be initialized to "" and the variable coinValue will be initialized to 0.
B) The variable coinName will be initialized to "null" and the variable coinValue will be initialized to 0.
C) The variable coinName will not be initialized but the variable coinValue will be initialized to 0.
D) The variable coinName will be initialized to null and the variable coinValue will be initialized to 0.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
44
If you do not provide a constructor in a class, which of the following is correct?
A) The compiler will generate a constructor with arguments for each class instance variable and will initialize all of the class instance variables.
B) The compiler will generate a constructor with no arguments.
C) The compiler will generate a constructor with arguments for each class instance variable.
D) The class code will not compile.
A) The compiler will generate a constructor with arguments for each class instance variable and will initialize all of the class instance variables.
B) The compiler will generate a constructor with no arguments.
C) The compiler will generate a constructor with arguments for each class instance variable.
D) The class code will not compile.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
45
Consider the following code snippet:
Public class Employee
{
Private String empID;
Private boolean hourly;
Public Employee()
{
}
) . .
}
Which statement reflects the action performed when the constructor to Employee is called?
A) The variable empID will be initialized to "" and the variable hourly will be initialized to false.
B) The variable empID will be initialized to "null" and the variable hourly will be initialized to true.
C) The variable empID will not be initialized but the variable hourly will be initialized to false.
D) The variable empID will be initialized to null and the variable hourly will be initialized to false.
Public class Employee
{
Private String empID;
Private boolean hourly;
Public Employee()
{
}
) . .
}
Which statement reflects the action performed when the constructor to Employee is called?
A) The variable empID will be initialized to "" and the variable hourly will be initialized to false.
B) The variable empID will be initialized to "null" and the variable hourly will be initialized to true.
C) The variable empID will not be initialized but the variable hourly will be initialized to false.
D) The variable empID will be initialized to null and the variable hourly will be initialized to false.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
46
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.
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
47
The object on which a method is invoked is called the ____.
A) interface
B) procedure
C) implicit parameter
D) explicit parameter
A) interface
B) procedure
C) implicit parameter
D) explicit parameter
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
48
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)
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)
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
49
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.
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
50
Consider the following code snippet:
Public class Vehicle
{
Private String type;
Public String Vehicle(String type)
{
) . .
}
}
What is wrong with this code?
A) The class instance variable type must be initialized when it is declared.
B) The constructor must not have any arguments.
C) The constructor must not have a return type declared.
D) The constructor's return type must be void.
Public class Vehicle
{
Private String type;
Public String Vehicle(String type)
{
) . .
}
}
What is wrong with this code?
A) The class instance variable type must be initialized when it is declared.
B) The constructor must not have any arguments.
C) The constructor must not have a return type declared.
D) The constructor's return type must be void.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
51
Consider the following code snippet:
Public class Vehicle
{
Private String type;
Private int numAxles;
Public Vehicle()
{
}
) . .
}
Which statement reflects the action performed when the constructor to Vehicle is called?
A) The variable type will be initialized to "" and the variable numAxles will be initialized to 0.
B) The variable type will be initialized to "null" and the variable numAxles will be initialized to 0.
C) The variable type will not be initialized but the variable numAxles will be initialized to 0.
D) The variable type will be initialized to null and the variable numAxles will be initialized to 0.
Public class Vehicle
{
Private String type;
Private int numAxles;
Public Vehicle()
{
}
) . .
}
Which statement reflects the action performed when the constructor to Vehicle is called?
A) The variable type will be initialized to "" and the variable numAxles will be initialized to 0.
B) The variable type will be initialized to "null" and the variable numAxles will be initialized to 0.
C) The variable type will not be initialized but the variable numAxles will be initialized to 0.
D) The variable type will be initialized to null and the variable numAxles will be initialized to 0.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
52
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.
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
53
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.
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
54
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
A) implicit parameters
B) interfaces
C) explicit parameters
D) return values
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
55
Consider the following code snippet:
Public class Vehicle
{
Private String type;
Private int numAxles;
Public Vehicle(String vehicleType, int VehicleAxles)
{ ) . . }
}
Which of the following statements can be used to create an object of type Vehicle?
A) Vehicle anAuto = new Vehicle();
B) Vehicle anAuto = new Vehicle(2, "SUV");
C) Vehicle anAuto = new Vehicle("SUV", "2");
D) Vehicle anAuto = new Vehicle("SUV", 2);
Public class Vehicle
{
Private String type;
Private int numAxles;
Public Vehicle(String vehicleType, int VehicleAxles)
{ ) . . }
}
Which of the following statements can be used to create an object of type Vehicle?
A) Vehicle anAuto = new Vehicle();
B) Vehicle anAuto = new Vehicle(2, "SUV");
C) Vehicle anAuto = new Vehicle("SUV", "2");
D) Vehicle anAuto = new Vehicle("SUV", 2);
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
56
You are creating a class named Vessel. Which statement correctly declares a constructor for this class?
A) public Vessel()
B) public void Vessel()
C) void Vessel()
D) new Vessel()
A) public Vessel()
B) public void Vessel()
C) void Vessel()
D) new Vessel()
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
57
Which of the following statements about constructors is correct?
A) A class can have only one constructor.
B) A constructor should always return a value.
C) A class must have at least one constructor supplied by the programmer.
D) A constructor must have the same name as the class.
A) A class can have only one constructor.
B) A constructor should always return a value.
C) A class must have at least one constructor supplied by the programmer.
D) A constructor must have the same name as the class.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
58
You are creating a class named Employee. Which statement correctly declares a constructor for this class?
A) public Employee()
B) public void Employee()
C) void Employee()
D) new Employee()
A) public Employee()
B) public void Employee()
C) void Employee()
D) new Employee()
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
59
Consider the following code snippet:
Public class Vessel
{
Private String type;
Public String Vessel(String type)
{
) . .
}
}
What is wrong with this code?
A) The class instance variable type must be initialized when it is declared.
B) The constructor must not have any arguments.
C) The constructor must not have a return type declared.
D) The constructor's return type must be void.
Public class Vessel
{
Private String type;
Public String Vessel(String type)
{
) . .
}
}
What is wrong with this code?
A) The class instance variable type must be initialized when it is declared.
B) The constructor must not have any arguments.
C) The constructor must not have a return type declared.
D) The constructor's return type must be void.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
60
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.
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.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
61
Consider the following code snippet:
Public class AutoRace
{
Private int lapCount;
Private double totalTime;
) . .
}
Which of the following completeLap methods would correctly track how many laps occurred?
A) public void completeLap(double lapTime)
{
TotalTime = totalTime + lapTime;
}
B) public void completeLap(double lapTime)
{
TotalTime = totalTime + lapTime;
LapCount ++;
}
C) public void completeLap(double lapTime)
{
TotalTime = totalTime + lapTime;
LapCount = lapCount + lapTime;
}
D) public void completeLap(double lapTime)
{
TotalTime = lapCount + lapTime;
}
Public class AutoRace
{
Private int lapCount;
Private double totalTime;
) . .
}
Which of the following completeLap methods would correctly track how many laps occurred?
A) public void completeLap(double lapTime)
{
TotalTime = totalTime + lapTime;
}
B) public void completeLap(double lapTime)
{
TotalTime = totalTime + lapTime;
LapCount ++;
}
C) public void completeLap(double lapTime)
{
TotalTime = totalTime + lapTime;
LapCount = lapCount + lapTime;
}
D) public void completeLap(double lapTime)
{
TotalTime = lapCount + lapTime;
}
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
62
Which of the following statements about testing a class is correct?
A) A unit test verifies that only one method within a class works correctly.
B) A unit test verifies that a class works correctly when it is in a complete program.
C) A unit test verifies that a class works correctly in isolation, outside a complete program.
D) A unit test does not need to know what results are expected.
A) A unit test verifies that only one method within a class works correctly.
B) A unit test verifies that a class works correctly when it is in a complete program.
C) A unit test verifies that a class works correctly in isolation, outside a complete program.
D) A unit test does not need to know what results are expected.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
63
Consider the following class:
Public class Auto
{
Private String make;
Private String model;
Private String year;
Public Auto(String aMake, String aModel, String aYear)
{
Make = aMake;
Model = aModel;
Year = aYear;
}
Public String calcMileage(double milesDriven, double gasUsed)
{
Double milage = milesDriven/gasUsed;
Return mileage.toString();
}
}
Which of the following code snippets will correctly create an object of type Auto and display its mileage?
A) myAuto = new Auto();
System.out.println(myAuto.calcMileage(246.0, 15.8));
B) Auto myAuto = new Auto();
System.out.println(myAuto.calcMileage(246.0, 15.8));
C) Auto myAuto = new Auto("2011", "Ford", "Focus");
System.out.println(myAuto.calcMileage(246.0, 15.8));
D) Auto myAuto = new Auto("Ford", "Focus", "2011");
System.out.println(myAuto.calcMileage(246.0, 15.8));
Public class Auto
{
Private String make;
Private String model;
Private String year;
Public Auto(String aMake, String aModel, String aYear)
{
Make = aMake;
Model = aModel;
Year = aYear;
}
Public String calcMileage(double milesDriven, double gasUsed)
{
Double milage = milesDriven/gasUsed;
Return mileage.toString();
}
}
Which of the following code snippets will correctly create an object of type Auto and display its mileage?
A) myAuto = new Auto();
System.out.println(myAuto.calcMileage(246.0, 15.8));
B) Auto myAuto = new Auto();
System.out.println(myAuto.calcMileage(246.0, 15.8));
C) Auto myAuto = new Auto("2011", "Ford", "Focus");
System.out.println(myAuto.calcMileage(246.0, 15.8));
D) Auto myAuto = new Auto("Ford", "Focus", "2011");
System.out.println(myAuto.calcMileage(246.0, 15.8));
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
64
Consider the following code snippet:
Public class Transaction
{
Private int transactionCount;
) . .
}
Which of the following methods would correctly keep track of the total number of transactions?
A) public void addTransactions(int newTransactions)
{
TransactionCount = newTransactions
}
B) public void addTransactions(int newTransactions)
{
TransactionCount = transactionCount + newTransactions
}
C) public void addTransactions(int newTransactions)
{
NewTransactions = transactionCount
}
D) public void addTransactions(int newTransactions)
{
NewTransactions = newTransactions + transactionCount
}
Public class Transaction
{
Private int transactionCount;
) . .
}
Which of the following methods would correctly keep track of the total number of transactions?
A) public void addTransactions(int newTransactions)
{
TransactionCount = newTransactions
}
B) public void addTransactions(int newTransactions)
{
TransactionCount = transactionCount + newTransactions
}
C) public void addTransactions(int newTransactions)
{
NewTransactions = transactionCount
}
D) public void addTransactions(int newTransactions)
{
NewTransactions = newTransactions + transactionCount
}
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
65
You have created a Fruit class and a ShoppingCart class. Which of the following methods will correctly add a Fruit object to an array list named fruits in the ShoppingCart class?
A) public void add(Fruit aFruit)
{
Fruits.add(new Fruit(aFruit));
}
B) public void add(Fruit aFruit)
{
Fruits.add(aFruit);
}
C) public void add(Fruit aFruit)
{
Fruits.addItem(new Fruit(aFruit));
}
D) public void add(Fruit aFruit)
{
Fruits.addItem(aFruit);
}
A) public void add(Fruit aFruit)
{
Fruits.add(new Fruit(aFruit));
}
B) public void add(Fruit aFruit)
{
Fruits.add(aFruit);
}
C) public void add(Fruit aFruit)
{
Fruits.addItem(new Fruit(aFruit));
}
D) public void add(Fruit aFruit)
{
Fruits.addItem(aFruit);
}
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
66
Consider the following code snippet:
Public class Course
{
Private int studentCount;
) . .
}
Which of the following methods would correctly keep track of the total number of enrollees in a course?
A) public void addEnrollees(int newEnrollees)
{
StudentCount = newEnrollees
}
B) public void addEnrollees(int newEnrollees)
{
StudentCount = studentCount + newEnrollees
}
C) public void addEnrollees(int newEnrollees)
{
NewEnrollees = studentCount
}
D) public void addEnrollees(int newEnrollees)
{
NewEnrollees = newEnrollees + studentCount
}
Public class Course
{
Private int studentCount;
) . .
}
Which of the following methods would correctly keep track of the total number of enrollees in a course?
A) public void addEnrollees(int newEnrollees)
{
StudentCount = newEnrollees
}
B) public void addEnrollees(int newEnrollees)
{
StudentCount = studentCount + newEnrollees
}
C) public void addEnrollees(int newEnrollees)
{
NewEnrollees = studentCount
}
D) public void addEnrollees(int newEnrollees)
{
NewEnrollees = newEnrollees + studentCount
}
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
67
Consider the following code snippet:
Public class Vehicle
{
Private String type;
Private int numAxles;
Public Vehicle(String vehicleType, int VehicleAxles) { . . . }
Public Vehicle(String vehicleType) { . . . }
}
What is wrong with this code?
A) There must be a default constructor with no arguments.
B) A class cannot have more than one constructor.
C) If a class has more than one constructor, each one should have a unique name.
D) There is nothing wrong with this code.
Public class Vehicle
{
Private String type;
Private int numAxles;
Public Vehicle(String vehicleType, int VehicleAxles) { . . . }
Public Vehicle(String vehicleType) { . . . }
}
What is wrong with this code?
A) There must be a default constructor with no arguments.
B) A class cannot have more than one constructor.
C) If a class has more than one constructor, each one should have a unique name.
D) There is nothing wrong with this code.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
68
You have created a Coin class and a Purse class. Which of the following methods will correctly add a Coin object to an array list named coins in the Purse class?
A) public void add(Coin aCoin)
{
Coins.add(new Coin(aCoin));
}
B) public void add(Coin aCoin)
{
Coins.add(aCoin);
}
C) public void add(Coin aCoin)
{
Coins.addItem(new Coin(aCoin));
}
D) public void add(Coin aCoin)
{
Coins.addItem(aCoin);
}
A) public void add(Coin aCoin)
{
Coins.add(new Coin(aCoin));
}
B) public void add(Coin aCoin)
{
Coins.add(aCoin);
}
C) public void add(Coin aCoin)
{
Coins.addItem(new Coin(aCoin));
}
D) public void add(Coin aCoin)
{
Coins.addItem(aCoin);
}
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
69
Consider the following code snippet:
Public class Vehicle
{
Private String type;
Private int numAxles;
Public void Vehicle(String vehicleType, int VehicleAxles)
{ ) . . }
}
What is wrong with this code?
A) There must be a default constructor with no arguments.
B) The class instance variables must be initialized in the declaration statements.
C) The constructor declaration must have a return type of String.
D) The constructor declaration must not have any return type.
Public class Vehicle
{
Private String type;
Private int numAxles;
Public void Vehicle(String vehicleType, int VehicleAxles)
{ ) . . }
}
What is wrong with this code?
A) There must be a default constructor with no arguments.
B) The class instance variables must be initialized in the declaration statements.
C) The constructor declaration must have a return type of String.
D) The constructor declaration must not have any return type.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
70
Insert the missing code in the following code fragment. This fragment is intended to implement a method to assign a value to an instance variable.
Public class Vehicle
{
Private String model;
Private double rpm;
) . .
_______
{
Model = modelName;
}
}
A) public void setModel(String modelName)
B) public void getModel()
C) public String getModel()
D) public String setModel(String modelName)
Public class Vehicle
{
Private String model;
Private double rpm;
) . .
_______
{
Model = modelName;
}
}
A) public void setModel(String modelName)
B) public void getModel()
C) public String getModel()
D) public String setModel(String modelName)
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
71
You have created a ShoppingCart class and a Fruit class. Which of the following will correctly declare an array list of Fruit objects in the ShoppingCart class?
A) public ShoppingCart
{
Private Fruit ArrayList fruits;
}
B) public ShoppingCart
{
Private ArrayList fruits;
}
C) public ShoppingCart
{
Private ArrayList fruits;
}
D) public ShoppingCart
{
Public ArrayList fruits;
}
A) public ShoppingCart
{
Private Fruit ArrayList fruits;
}
B) public ShoppingCart
{
Private ArrayList fruits;
}
C) public ShoppingCart
{
Private ArrayList
}
D) public ShoppingCart
{
Public ArrayList
}
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
72
Consider the following code snippet:
Public class Vehicle
{
Private String model;
Private double rpm;
) . .
}
Which of the following methods would correctly remove the values of the class instance variables?
A) public void reset()
{
Model = null;
Rpm = 0;
}
B) public void reset()
{
Model.clear();
Rpm = 0;
}
C) public void reset(String aModel, double theRpm)
{
Model = aModel;
Rpm = theRpm;
}
D) public void reset("",0)
{
}
Public class Vehicle
{
Private String model;
Private double rpm;
) . .
}
Which of the following methods would correctly remove the values of the class instance variables?
A) public void reset()
{
Model = null;
Rpm = 0;
}
B) public void reset()
{
Model.clear();
Rpm = 0;
}
C) public void reset(String aModel, double theRpm)
{
Model = aModel;
Rpm = theRpm;
}
D) public void reset("",0)
{
}
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
73
Which of the following statements using data values in a class is NOT correct?
A) You can use an instance variable's data value in an instance method.
B) You can use the argument of an instance method in that method.
C) You can use a global constant's value in an instance method.
D) You can use the argument of any instance method in any other method.
A) You can use an instance variable's data value in an instance method.
B) You can use the argument of an instance method in that method.
C) You can use a global constant's value in an instance method.
D) You can use the argument of any instance method in any other method.
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
74
Consider the following class:
Public class Auto
{
Private String make;
Private String model;
Private String year;
Public Auto(String aMake, String aModel, String aYear)
{
Make = aMake;
Model = aModel;
Year = aYear;
}
Public String getInfo()
{
Return year + " " + make + " " + model;
}
}
Which of the following code snippets will correctly create an object of this class and display its information?
A) myAuto = new Auto();
System.out.println(myAuto.getInfo());
B) Auto myAuto = new Auto();
System.out.println(myAuto.getInfo());
C) Auto myAuto = new Auto("Ford", "Focus", "2011");
System.out.println(myAuto.getInfo());
D) Auto myAuto = new Auto("2011", "Ford", "Focus");
System.out.println(myAuto.getInfo());
Public class Auto
{
Private String make;
Private String model;
Private String year;
Public Auto(String aMake, String aModel, String aYear)
{
Make = aMake;
Model = aModel;
Year = aYear;
}
Public String getInfo()
{
Return year + " " + make + " " + model;
}
}
Which of the following code snippets will correctly create an object of this class and display its information?
A) myAuto = new Auto();
System.out.println(myAuto.getInfo());
B) Auto myAuto = new Auto();
System.out.println(myAuto.getInfo());
C) Auto myAuto = new Auto("Ford", "Focus", "2011");
System.out.println(myAuto.getInfo());
D) Auto myAuto = new Auto("2011", "Ford", "Focus");
System.out.println(myAuto.getInfo());
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
75
Insert the missing code in the following code fragment. This fragment is intended to implement a method to get the value stored in an instance variable.
Public class Employee
{
Private String empID;
Private boolean hourly;
) . .
_______
{
Return hourly;
}
}
A) public void setHourly(String isHourly)
B) public void getHourly()
C) public boolean getHourly()
D) public boolean setHourly(boolean isHourly)
Public class Employee
{
Private String empID;
Private boolean hourly;
) . .
_______
{
Return hourly;
}
}
A) public void setHourly(String isHourly)
B) public void getHourly()
C) public boolean getHourly()
D) public boolean setHourly(boolean isHourly)
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
76
Consider the following code snippet:
Public class Employee
{
Private String empID;
Private boolean hourly;
Public Employee(String employeeID, boolean isHourly)
{ ) . . }
}
Which of the following statements can be used to create an object of type Employee?
A) Employee anAuto = new Employee();
B) Employee anAuto = new Employee(10548, true);
C) Employee anAuto = new Employee("10548", true);
D) Employee anAuto = new Employee(10548, "true");
Public class Employee
{
Private String empID;
Private boolean hourly;
Public Employee(String employeeID, boolean isHourly)
{ ) . . }
}
Which of the following statements can be used to create an object of type Employee?
A) Employee anAuto = new Employee();
B) Employee anAuto = new Employee(10548, true);
C) Employee anAuto = new Employee("10548", true);
D) Employee anAuto = new Employee(10548, "true");
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
77
You have created a Coin class and a Purse class. Which of the following will correctly allow the Purse class to collect Coin objects?
A) public Purse
{
Private Coin ArrayList coins;
}
B) public Purse
{
Private ArrayList coins;
}
C) public Purse
{
Private ArrayList coins;
}
D) public Purse
{
Public ArrayList coins;
}
A) public Purse
{
Private Coin ArrayList coins;
}
B) public Purse
{
Private ArrayList coins;
}
C) public Purse
{
Private ArrayList
}
D) public Purse
{
Public ArrayList
}
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
78
Insert the missing code in the following code fragment. This fragment is intended to implement a method to get the value stored in an instance variable.
Public class Vehicle
{
Private String model;
Private double rpm;
) . .
_______
{
Return model;
}
}
A) public void setModel(String modelName)
B) public void getModel()
C) public String getModel()
D) public String setModel(String modelName)
Public class Vehicle
{
Private String model;
Private double rpm;
) . .
_______
{
Return model;
}
}
A) public void setModel(String modelName)
B) public void getModel()
C) public String getModel()
D) public String setModel(String modelName)
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
79
Consider the following code snippet:
Public class BankAccount
{
Private int transactionCount;
Private double balance;
) . .
}
Which of the following deposit methods would correctly track how many deposits occurred?
A) public void deposit(double amount)
{
Balance = balance + amount;
}
B) public void deposit(double amount)
{
Balance = balance + amount;
TransactionCount ++;
}
C) public void deposit(double amount)
{
Balance = balance + amount;
TransactionCount = transactionCount + amount;
}
D) public void deposit(double amount)
{
Balance = transactionCount + amount;
}
Public class BankAccount
{
Private int transactionCount;
Private double balance;
) . .
}
Which of the following deposit methods would correctly track how many deposits occurred?
A) public void deposit(double amount)
{
Balance = balance + amount;
}
B) public void deposit(double amount)
{
Balance = balance + amount;
TransactionCount ++;
}
C) public void deposit(double amount)
{
Balance = balance + amount;
TransactionCount = transactionCount + amount;
}
D) public void deposit(double amount)
{
Balance = transactionCount + amount;
}
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck
80
Complete the following code snippet to create a constructor that will initialize the class instance variables shown using data provided by the program which is creating an object from this class.
Public class Employee
{
Private String empID;
Private boolean hourly;
_______________________
{ ) . . }
}
Which of the following statements can be used to create an object of type Employee?
A) public Employee(String employeeID, boolean isHourly)
B) public Employee(employeeID, isHourly)
C) public Employee(empID, Hourly)
D) public Employee()
Public class Employee
{
Private String empID;
Private boolean hourly;
_______________________
{ ) . . }
}
Which of the following statements can be used to create an object of type Employee?
A) public Employee(String employeeID, boolean isHourly)
B) public Employee(employeeID, isHourly)
C) public Employee(empID, Hourly)
D) public Employee()
Unlock Deck
Unlock for access to all 101 flashcards in this deck.
Unlock Deck
k this deck