Deck 3: Implementing 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/108
Play
Full screen (f)
Deck 3: Implementing Classes
1
The access specifier in the declaration of instance variables should be ___.
A)protected
B)class
C)public
D)private
A)protected
B)class
C)public
D)private
protected
2
What statement is used to specify the value that a method gives back to its caller?
A)new
B)public
C)private
D)return
A)new
B)public
C)private
D)return
return
3
An instance variable declaration consists of which of the following parts?
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.
an access specifier, a list of the parameters (if any), and the body of the method.
4
Encapsulation allows a programmer to use a class without having to know its ____.
A)interface
B)name
C)methods
D)implementation
A)interface
B)name
C)methods
D)implementation
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
5
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 static int sideLength;
A)private integer sideLength;
B)private int sideLength;
C)public integer sideLength;
D)public static int sideLength;
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
6
Which part of a class implementation contains the instructions to initialize an object's instance variables?
A)constructor
B)access specifier
C)initializer
D)type name
A)constructor
B)access specifier
C)initializer
D)type name
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
7
What is the return type of the println method of the PrintStream class?
A)void
B)public
C)String
D)double
A)void
B)public
C)String
D)double
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
8
The black boxes from which a program is manufactured are called ___.
A)objects
B)access specifiers
C)methods
D)instance variables
A)objects
B)access specifiers
C)methods
D)instance variables
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
9
Which statement describes a central benefit of information hiding?
A)Easier to change the private implementation
B)Easier to change the method headers
C)Easier to change the name of the class
D)Easier to change the public interface
A)Easier to change the private implementation
B)Easier to change the method headers
C)Easier to change the name of the class
D)Easier to change the public interface
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
10
What is the name of the instance variable for a Counter object?
A)getValue
B)click
C)concertCounter
D)value
A)getValue
B)click
C)concertCounter
D)value
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
11
Which of the following statements is true about constructors?
A)Providing a constructor for a class is optional.
B)You can only provide one constructor for a class.
C)The body of the constructor must initialize all instance variables or the constructor will not successfully compile.
D)A constructor has a void return type.
A)Providing a constructor for a class is optional.
B)You can only provide one constructor for a class.
C)The body of the constructor must initialize all instance variables or the constructor will not successfully compile.
D)A constructor has a void return type.
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
12
Which term means the process of hiding object data and providing methods for data access?
A)documentation
B)encapsulation
C)instantiation
D)abstraction
A)documentation
B)encapsulation
C)instantiation
D)abstraction
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
13
Which of the following is a valid constructor header for the Player class that accepts the player name as a parameter?
A)public void Player(String playerName)
B)private Player(playerName)
C)private void Player(playerName)
D)public Player(String playerName)
A)public void Player(String playerName)
B)private Player(playerName)
C)private void Player(playerName)
D)public Player(String playerName)
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
14
The class constructor always has the same name as __.
A)access specifier
B)class
C)instance variable
D)parameter variable
A)access specifier
B)class
C)instance variable
D)parameter variable
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
15
What is the return type of a constructor?
A)void
B)A constructor does not have a return type.
C)private
D)public
A)void
B)A constructor does not have a return type.
C)private
D)public
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
16
A method header consists of which of the following parts?
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)the type of the instance variable, an access specifier, and a list of the parameters (if any)
D)an access specifier, 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)an access specifier, the type of the instance variable, and the name of the instance variable
C)the type of the instance variable, an access specifier, and a list of the parameters (if any)
D)an access specifier, a return type, a method name, and a list of the parameters (if any)
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
17
A class declaration consists of which of the following parts?
A)an access specifier, the keyword class, the name of the class, declarations for instance variables, constructors, and methods
B)an access specifier, a return type, a method name, a list of the parameters (if any), and the body of the method
C)the name of the class, declarations for instance variables, constructors, and methods
D)an access specifier, the name of the class, a list of the parameters (if any), and the body of the constructor
A)an access specifier, the keyword class, the name of the class, declarations for instance variables, constructors, and methods
B)an access specifier, a return type, a method name, a list of the parameters (if any), and the body of the method
C)the name of the class, declarations for instance variables, constructors, and methods
D)an access specifier, the name of the class, a list of the parameters (if any), and the body of the constructor
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
18
Which of the following corresponds to a valid constructor header for the Player class?
A)public Player()
B)public int Player
C)public void Player()
D)private void Player()
A)public Player()
B)public int Player
C)public void Player()
D)private void Player()
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
19
Each object of a class has its own set of ___.
A)methods
B)instance variables
C)constructors
D)classes
A)methods
B)instance variables
C)constructors
D)classes
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
20
What mechanism does an object use to store its data?
A)files
B)methods
C)instance variables
D)access specifiers
A)files
B)methods
C)instance variables
D)access specifiers
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
21
Consider the following method comment and method header:
Fill in the blank.
A)return double
B)return
C)@return double
D)@return

A)return double
B)return
C)@return double
D)@return
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
22
We want to change the BankAccount class so that all accounts will have a monthly fee.The instance variable monthlyFee will hold the monthly fee.Which of the following constructors properly sets the monthly fee to a default value of 20?
A) public BankAccount (double initialBalance)
{
balance = initialBalance;
monthlyFee = 20;
}
B) public Bankaccount (double initialBalance)
{
balance = initialBalance;
double monthlyFee = 20;
}
C) public BankAccount (double initialBalance)
{
balance = initialBalance;
monthlyFee = initialBalance-20;
}
D) public BankAccount (double initialBalance)
{
balance = initialBalance-20;
}
A) public BankAccount (double initialBalance)
{
balance = initialBalance;
monthlyFee = 20;
}
B) public Bankaccount (double initialBalance)
{
balance = initialBalance;
double monthlyFee = 20;
}
C) public BankAccount (double initialBalance)
{
balance = initialBalance;
monthlyFee = initialBalance-20;
}
D) public BankAccount (double initialBalance)
{
balance = initialBalance-20;
}
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
23
We want to create a class that represents a geometric sequence.A geometric sequence is a sequence of numbers that begin at some value and then multiplies each value by some constant to get the next value.For example, the geometric sequence 1, 2, 4, 8, 16 starts at 1 and multiplies each term by 2 to get the next.The geometric sequence 10.8, 5.4, 2.7, 1.35 starts at 10.8 and multiplies each term by 0.5 to get the next.The basic framework of a geometric sequence class is below:
Which of the constructor specifications below will allow this code to behave as desired?
A)public void GeometricSequence(double initial, double mult)
B)public GeometricSequence init(double initial, double mult)
C)public GeometricSequence GeometricSequence(double initial, double mult)
D)public GeometricSequence(double initial, double mult)

A)public void GeometricSequence(double initial, double mult)
B)public GeometricSequence init(double initial, double mult)
C)public GeometricSequence GeometricSequence(double initial, double mult)
D)public GeometricSequence(double initial, double mult)
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
24
What is the name of the utility that formats comments into a set of documents that you can view in a Web browser?
A)javadoc
B)javac
C)javad
D)java
A)javadoc
B)javac
C)javad
D)java
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
25
What are the operations that any programmer can use to create and manipulate objects of the class called?
A)public implementation
B)public interface
C)private implementation
D)private interface
A)public implementation
B)public interface
C)private implementation
D)private interface
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
26
The javadoc utility is used to
A)assist the compiler in checking the syntax of the Java program.
B)ensure that comments are appropriately descriptive.
C)automatically generate HTML pages that describe classes.
D)convert the Java program into machine-executable code.
A)assist the compiler in checking the syntax of the Java program.
B)ensure that comments are appropriately descriptive.
C)automatically generate HTML pages that describe classes.
D)convert the Java program into machine-executable code.
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
27
Consider the following code to declare a constructor for the Player class:
Which statement is true?
A)The code compiles successfully and results in the instantiation of a Player object when called.
B)The code compiles successfully but results in a logic error in the code that calls the method.
C)The code does not compile.
D)The code compiles successfully but results in a run-time error in the code that calls the constructor.

A)The code compiles successfully and results in the instantiation of a Player object when called.
B)The code compiles successfully but results in a logic error in the code that calls the method.
C)The code does not compile.
D)The code compiles successfully but results in a run-time error in the code that calls the constructor.
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
28
Which of the following corresponds to the getArea method header for a Square class assuming an integer value for a side length?
A)public int getArea
B)public integer getArea
C)public int getArea()
D)public integer getArea()
A)public int getArea
B)public integer getArea
C)public int getArea()
D)public integer getArea()
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
29
What is the name of the constructor for the BankAccount class?
A)BankAccount
B)deposit
C)balance
D)withdraw
A)BankAccount
B)deposit
C)balance
D)withdraw
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
30
We want to create a class that represents a geometric sequence.A geometric sequence is a sequence of numbers that begin at some value and then multiplies each value by some constant to get the next value.For example, the geometric sequence 1, 2, 4, 8, 16 starts at 1 and multiplies each term by 2 to get the next.The geometric sequence 10.8, 5.4, 2.7, 1.35 starts at 10.8 and multiplies each term by 0.5 to get the next.The basic framework of a geometric sequence class is below:
A)public next() : double
B)public int next()
C)public void next(double result)
D)public double next()

A)public next() : double
B)public int next()
C)public void next(double result)
D)public double next()
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
31
Consider the following method comment and method header:
Fill in the blank.
A)return
B)fromMeasurement
C)double
D)convertTo

A)return
B)fromMeasurement
C)double
D)convertTo
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
32
We want to change the BankAccount class so that all accounts will have a monthly fee.Which of the following will properly define the instance variable monthlyFee that holds the monthly fee?
A)monthlyFee: double;
B)instance var monthlyFee;
C)private double monthlyFee;
D)private field monthlyFee;
A)monthlyFee: double;
B)instance var monthlyFee;
C)private double monthlyFee;
D)private field monthlyFee;
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
33
Which special delimeter is used with the javadoc utility to document method arguments?
A)/**
B)@param
C)@return
D)@javadoc
A)/**
B)@param
C)@return
D)@javadoc
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
34
.Consider the following method comment and method header:
Fill in the blank.
A)@param
B)param
C)@parameter
D)parameter

A)@param
B)param
C)@parameter
D)parameter
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
35
Why is it a good idea for a programmer to write comments about a method first, before implementing it?
A)It is a good idea for complex methods, but not simple ones.
B)It can help to assign good variable names.
C)Without comments it is not possible to compile the code.
D)It is an excellent test to ensure that the programmer firmly understands what is needed.
A)It is a good idea for complex methods, but not simple ones.
B)It can help to assign good variable names.
C)Without comments it is not possible to compile the code.
D)It is an excellent test to ensure that the programmer firmly understands what is needed.
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
36
We want to create a class that represents a geometric sequence.A geometric sequence is a sequence of numbers that begin at some value and then multiplies each value by some constant to get the next value.For example, the geometric sequence 1, 2, 4, 8, 16 starts at 1 and multiplies each term by 2 to get the next.The geometric sequence 10.8, 5.4, 2.7, 1.35 starts at 10.8 and multiplies each term by 0.5 to get the next.The basic framework of a geometric sequence class is below: public class Geometricsequence
{
private double currentValue;
private double multiplier;
}
Assume that the parameters to the constructor are initial and mult. What should the body of the constructor be?
A) currentvalue = initial;
multiplier = mult;
B) initial = currentValue;
mult = multiplier;
C) double currentValue = initial;
double multiplier = mult;
D) double initial = currentValue;
double mult = multiplier;
{
private double currentValue;
private double multiplier;
}
Assume that the parameters to the constructor are initial and mult. What should the body of the constructor be?
A) currentvalue = initial;
multiplier = mult;
B) initial = currentValue;
mult = multiplier;
C) double currentValue = initial;
double multiplier = mult;
D) double initial = currentValue;
double mult = multiplier;
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
37
We want to change the BankAccount class so that all accounts will have a monthly fee.The instance variable monthlyFee will hold the monthly fee.Which of the following is the correct public interface for a constructor that sets both the initial balance and monthly fee?
A) public BankAccount (double initialBalance, monthlyFee)
B) public BankAccount (double initialBalance, double monthlyFee)
C) public Bankaccount (double initialBalance) has monthlyFee
D) public BankAccount (double initialBalance)
{
double monthlyFee;
/ / The rest of the constructor code follows
}
A) public BankAccount (double initialBalance, monthlyFee)
B) public BankAccount (double initialBalance, double monthlyFee)
C) public Bankaccount (double initialBalance) has monthlyFee
D) public BankAccount (double initialBalance)
{
double monthlyFee;
/ / The rest of the constructor code follows
}
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
38
What is the purpose of a clean and concise design for an object's public interface?
A)Allows the compiler to function more efficiently.
B)Supports cross-platform independence.
C)Allows programmers to design solutions using the object without needing to know the details of the class implementation.
D)Eliminates the need to provide any documentation in the code.
A)Allows the compiler to function more efficiently.
B)Supports cross-platform independence.
C)Allows programmers to design solutions using the object without needing to know the details of the class implementation.
D)Eliminates the need to provide any documentation in the code.
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
39
We want to change the BankAccount class so that all accounts will have a monthly fee.The instance variable monthlyFee will hold the monthly fee.Which of the following methods deducts the value of the monthly fee from the account?
A) public void chargefee()
{
balance = balance - monthlyFee;
}
B) public void chargefee()
{
initialBalance = initialBalance - monthlyFee;
}
C) public void chargeFee()
{
balance = monthlyFee;
}
D) public void chargefee()
{
balance - monthlyFee;
}
A) public void chargefee()
{
balance = balance - monthlyFee;
}
B) public void chargefee()
{
initialBalance = initialBalance - monthlyFee;
}
C) public void chargeFee()
{
balance = monthlyFee;
}
D) public void chargefee()
{
balance - monthlyFee;
}
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
40
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 108 flashcards in this deck.
Unlock Deck
k this deck
41
Which line of code is part of the public implementation of the BankAccount class?
A)balance = balance + amount;
B)balance = balance - amount;
C)public BankAccount(double initialBalance)
D)return balance;
A)balance = balance + amount;
B)balance = balance - amount;
C)public BankAccount(double initialBalance)
D)return balance;
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
42
You should provide documentation comments for ___.
A)only classes
B)only methods with parameters
C)every class, every method, every parameter, and every return value
D)only methods with return values
A)only classes
B)only methods with parameters
C)every class, every method, every parameter, and every return value
D)only methods with return values
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
43
If a method has two parameters, one explicit and one implicit, and a return type of void, then the documentation comments should include:
A)One @param statement, and one @return statement
B)Two @param statements, and one @return statement
C)One @param statement, and no @return statement
D)Two @param statements, and no @return statement
A)One @param statement, and one @return statement
B)Two @param statements, and one @return statement
C)One @param statement, and no @return statement
D)Two @param statements, and no @return statement
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
44
We want to create a class that represents a geometric sequence.A geometric sequence is a sequence of numbers that begin at some value and then multiplies each value by some constant to get the next value.For example, the geometric sequence 1, 2, 4, 8, 16 starts at 1 and multiplies each term by 2 to get the next.The geometric sequence 10.8, 5.4, 2.7, 1.35 starts at 10.8 and multiplies each term by 0.5 to get the next.The basic framework of a geometric sequence class is below: public class Geometricsequence
{
private double currentvalue;
private double multiplier;
}
We want to create a geometric sequence using code like:
Geometricsequence first = new Geometricsequence (1,2);
// Creates 1, 2, 4, 8, 16...
Geometricsequence second = new Geometricsequence (10.8,0.5);
/ / Creates 10.8,5.4,2.7,1.35 ...
We want to produce elements of the geometric sequence using code code like:
System.out.println (first.next()); // Prints 1 and advances
System.out.println (first.next()); // Prints 2 and advances
System.out.println (first.next()); // Prints 4 and advances
System.out.println (first.next()); // Prints 8 and advances
System.out.println (second.next()); //Prints 10.8 and advances
System.out.println (second.next()); //Prints 5.4 and advances
System.out.println (second.next()); //Prints 2.7 and advances
What should the body of the next method be?
A) double result = currentValue;
currentvalue = currentValue * multiplier;
return result;
B) return currentValue;
currentValue = currentValue * multiplier;
C) double result = currentValue;
multiplier = currentValue * multiplier;
return result;
D) currentValue = currentValue * multiplier;
return currentValue;
{
private double currentvalue;
private double multiplier;
}
We want to create a geometric sequence using code like:
Geometricsequence first = new Geometricsequence (1,2);
// Creates 1, 2, 4, 8, 16...
Geometricsequence second = new Geometricsequence (10.8,0.5);
/ / Creates 10.8,5.4,2.7,1.35 ...
We want to produce elements of the geometric sequence using code code like:
System.out.println (first.next()); // Prints 1 and advances
System.out.println (first.next()); // Prints 2 and advances
System.out.println (first.next()); // Prints 4 and advances
System.out.println (first.next()); // Prints 8 and advances
System.out.println (second.next()); //Prints 10.8 and advances
System.out.println (second.next()); //Prints 5.4 and advances
System.out.println (second.next()); //Prints 2.7 and advances
What should the body of the next method be?
A) double result = currentValue;
currentvalue = currentValue * multiplier;
return result;
B) return currentValue;
currentValue = currentValue * multiplier;
C) double result = currentValue;
multiplier = currentValue * multiplier;
return result;
D) currentValue = currentValue * multiplier;
return currentValue;
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
45
Given this method implementation, fill in the blank in the method comment.
A)parameter
B)@param
C)param
D)@parameter

A)parameter
B)@param
C)param
D)@parameter
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
46
Descriptive text used to communicate design and implementation issues about the classes and public methods of programs is called _______?
A)components
B)comments
C)constants
D)commands
A)components
B)comments
C)constants
D)commands
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
47
Which line of code is part of the private implementation of the BankAccount class?
A)public BankAccount()
B)balance = balance - amount;
C)public void deposit(double amount)
D)public void withdraw(double amount)
A)public BankAccount()
B)balance = balance - amount;
C)public void deposit(double amount)
D)public void withdraw(double amount)
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
48
Given this method comment, fill in the blank in the method implementation.
A)double
B)void
C)return
D)null

A)double
B)void
C)return
D)null
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
49
Choose the method header that goes with this method comment.
A)public void raiseSalary(double percent)
B)public double raiseSalary(double percent)
C)public double raiseSalary(double percentRaise)
D)public void raiseSalary(double percentRaise)

A)public void raiseSalary(double percent)
B)public double raiseSalary(double percent)
C)public double raiseSalary(double percentRaise)
D)public void raiseSalary(double percentRaise)
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
50
Choose the method header that goes with this method comment.
A)public void getSalary()
B)public void getSalary
C)public double getSalary()
D)public double getSalary

A)public void getSalary()
B)public void getSalary
C)public double getSalary()
D)public double getSalary
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
51
Consider the following method header for the BankAccount class:
Fill in the blank in the method body.
A)balance = balance * (1 + rate);
B)balance = balance * rate;
C)balance = balance * (1 + interestRate);
D)balance = balance * interestRate;

A)balance = balance * (1 + rate);
B)balance = balance * rate;
C)balance = balance * (1 + interestRate);
D)balance = balance * interestRate;
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
52
Consider the following method header for an Employee class:
Fill in the blank in the method body with the implementation that will change the instance variable salary to reflect the employee's new salary after applying the raise:
A)salary = salary * (1 + percentRaise);
B)salary = salary * percentRaise;
C)salary = salary * raise;
D)salary = salary * (1 + raise);

A)salary = salary * (1 + percentRaise);
B)salary = salary * percentRaise;
C)salary = salary * raise;
D)salary = salary * (1 + raise);
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
53
Consider the following method header:
Fill in the blank in the javadoc comment:
A)@param rate the rate of interest
B)@parameter rate the rate of interest
C)@param interestRate the rate of interest
D)@parameter interestRate the rate of interest

A)@param rate the rate of interest
B)@parameter rate the rate of interest
C)@param interestRate the rate of interest
D)@parameter interestRate the rate of interest
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
54
When you declare a method, you also need to provide the method ____, which consists of statements that are executed when the method is called.
A)body
B)header
C)return type
D)access specifier
A)body
B)header
C)return type
D)access specifier
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
55
The private implementation of a class consists of ___.
A)instance variables and the method headers
B)local variables and the method headers
C)parameter variables and the method bodies
D)instance variables and the implementation of the constructors and methods
A)instance variables and the method headers
B)local variables and the method headers
C)parameter variables and the method bodies
D)instance variables and the implementation of the constructors and methods
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
56
Fill in the blank in the following method comment.
A)amount
B)balance
C)double amount
D)money

A)amount
B)balance
C)double amount
D)money
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
57
Given this method implementation, fill in the blank in the method comment.
A)return
B)double
C)@return
D)balance

A)return
B)double
C)@return
D)balance
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
58
Given this method comment, fill in the blank in the method implementation.
A)balance
B)@return
C)double
D)return

A)balance
B)@return
C)double
D)return
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
59
Fill in the blank in the comment for this method header.
A)@return double the interest
B)return the interest
C)@return the interest
D)return double the interest

A)@return double the interest
B)return the interest
C)@return the interest
D)return double the interest
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
60
Given this method comment, fill in the blank in the method implementation.
A)amount
B)parameter
C)initialBalance
D)balance

A)amount
B)parameter
C)initialBalance
D)balance
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
61
What is a local variable?
A)A variable that is declared in the header of a class.
B)A variable that is declared in the body of the class.
C)A variable that is declared in the header of a method.
D)A variable that is declared in the body of a method.
A)A variable that is declared in the header of a class.
B)A variable that is declared in the body of the class.
C)A variable that is declared in the header of a method.
D)A variable that is declared in the body of a method.
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
62
When using index cards to help with the tracing of the execution of an object by hand, what is written on the front of the card?
A)The names of all known tester classes for the object.
B)The key equations implemented by the constructor.
C)A table with the values of all of the instance variables.
D)The methods that the object can execute.
A)The names of all known tester classes for the object.
B)The key equations implemented by the constructor.
C)A table with the values of all of the instance variables.
D)The methods that the object can execute.
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
63
When tracing the execution of an object by hand, what is one way to indicate the change of an instance variable when a mutator method is executed?
A)Add a new index card for each change.
B)Cross out the old value and write down the new value.
C)Turn the card over and check the "mutator" box.
D)Put a check mark in the upper left corner of the index card.
A)Add a new index card for each change.
B)Cross out the old value and write down the new value.
C)Turn the card over and check the "mutator" box.
D)Put a check mark in the upper left corner of the index card.
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
64
What verifies that a class works correctly in isolation, outside a complete program?
A)unit test
B)encapsulation
C)abstraction
D)enumeration
ůDifficulty
Easy
A)unit test
B)encapsulation
C)abstraction
D)enumeration
ůDifficulty
Easy
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
65
When using index cards to help with the tracing of the execution of an object by hand, what is written on the back of the card?
A)The names of all known tester classes for the object.
B)The key equations implemented by the constructor.
C)A table with the values of all of the instance variables.
D)The methods that the object can execute.
A)The names of all known tester classes for the object.
B)The key equations implemented by the constructor.
C)A table with the values of all of the instance variables.
D)The methods that the object can execute.
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
66
Fill in the first line of this SquareTester program so that it declares and initializes a variable mySquare as an instance of a Square class with a side length of 6.
A)Square mySquare = new Square(6);
B)mySquare = new Square(6);
C)mySquare = Square(6);
D)Square mySquare = Square(6);

A)Square mySquare = new Square(6);
B)mySquare = new Square(6);
C)mySquare = Square(6);
D)Square mySquare = Square(6);
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
67
When a method exits, its ____ are removed.
A)local variables
B)classes
C)comments
D)instance variables
A)local variables
B)classes
C)comments
D)instance variables
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
68
Complete the following tester program by choosing the line that prints the expected outcome.
A)System.out.println("Expected: 1000");
B)System.out.println("Expected: 2000");
C)System.out.println("Expected: 2000")
D)println("Expected: 2000");

A)System.out.println("Expected: 1000");
B)System.out.println("Expected: 2000");
C)System.out.println("Expected: 2000")
D)println("Expected: 2000");
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
69
What is a tester class?
A)A class that constructs objects.
B)A class that invokes one or more methods.
C)A class that is named Tester.
D)A class with a main method that contains statements to run methods of another class.
A)A class that constructs objects.
B)A class that invokes one or more methods.
C)A class that is named Tester.
D)A class with a main method that contains statements to run methods of another class.
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
70
Fill in the third line of this SquareTester program so that it prints out the expected outcome.
A)System.out.println("Expected: 12");
B)System.out.println("Expected: 6");
C)System.out.println("Expected: 36");
D)System.out.println("Expected: 18");

A)System.out.println("Expected: 12");
B)System.out.println("Expected: 6");
C)System.out.println("Expected: 36");
D)System.out.println("Expected: 18");
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
71
What is the name of the local variable of the giveChange method of the CashRegister class?
A)amount
B)change
C)payment
D)purchase
A)amount
B)change
C)payment
D)purchase
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
72
Which of the following is an instance variable of the CashRegister class?
A)amount
B)balance
C)change
D)purchase
A)amount
B)balance
C)change
D)purchase
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
73
Fill in the blank in the comment for this method header.
A)@return the player
B)@parameter playerName the name of the player
C)@param playerName the name of the player
D)return the player

A)@return the player
B)@parameter playerName the name of the player
C)@param playerName the name of the player
D)return the player
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
74
Where do parameters and local variables belong?
A)in an object
B)in a class
C)in a method
D)in a package
A)in an object
B)in a class
C)in a method
D)in a package
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
75
Which of the following corresponds to the constructor body for a Square class that accepts an initial side length value called initialLength where the instance variable is named sideLength?
A)sideLength = initialLength;
B)initialLength = sideLength;
C)initialLength = 0;
D)sideLength = 0;
A)sideLength = initialLength;
B)initialLength = sideLength;
C)initialLength = 0;
D)sideLength = 0;
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
76
The code below for the mutator method public void setLength(double length) of the Square class is intended to set the value of the sideLength instance variable to the parameter variable of the method.Which line of code avoids the common error of ignoring the parameter variables of a method?
A)sideLength = 54;
B)return sideLength;
C)sideLength = length;
D)double thisLength = length;
A)sideLength = 54;
B)return sideLength;
C)sideLength = length;
D)double thisLength = length;
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
77
What is the name of the parameter variable of the recordPurchase method of the CashRegister class?
A)amount
B)payment
C)purchase
D)change
A)amount
B)payment
C)purchase
D)change
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
78
What is a parameter variable?
A)A variable that is declared in the header of a method.
B)A variable that is declared in the body of the class.
C)A variable that is declared in the body of a method.
D)A variable that is declared in the header of a class.
A)A variable that is declared in the header of a method.
B)A variable that is declared in the body of the class.
C)A variable that is declared in the body of a method.
D)A variable that is declared in the header of a class.
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
79
Where are instance variables properly declared?
A)the body of an object
B)the constructor of a class
C)the body of any method
D)in a package
A)the body of an object
B)the constructor of a class
C)the body of any method
D)in a package
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck
80
Which of the following corresponds to the getArea method body for a Square class where the instance variable is named sideLength?
A)return sideLength;
B)return area;
C)return width * height;
D)return sideLength * sideLength;
A)return sideLength;
B)return area;
C)return width * height;
D)return sideLength * sideLength;
Unlock Deck
Unlock for access to all 108 flashcards in this deck.
Unlock Deck
k this deck