Deck 8: Designing Classes

Full screen (f)
exit full mode
Question
A UML class diagram would be most useful in visually illustrating which of the following?

A) the cohesiveness of a class's interface.
B) the amount of complexity of a class's interface.
C) dependencies between classes.
D) relationships between classes and their interfaces.
Use Space or
up arrow
down arrow
to flip the card.
Question
The String class is an example of which of the following types of classes?

A) Static class.
B) Immutable class.
C) Abstract class.
D) Mutable class.
Question
General Java variable naming conventions would suggest that a variable named NICKEL_VALUE would most probably be declared using which of the following combinations of modifiers?

A) public void final
B) public static final double
C) private static double
D) private static
Question
Under which of the following conditions would the public interface of a class be considered cohesive?

A) All of its features are public and none of its features are static.
B) The quality of the public interface is rated as moderate to high.
C) All of its features are related to the concept that the class represents.
D) It is obvious that the public interface refers to multiple concepts.
Question
Which type of method modifies the object on which it is invoked?

A) Constructor method.
B) Static method.
C) Accessor method.
D) Mutator method.
Question
A class (ClassOne) is considered to have a dependency on another class (ClassTwo) under which of the following conditions?

A) Each class uses objects of the other.
B) The public interfaces of both classes are cohesive.
C) ClassTwo uses objects of ClassOne.
D) ClassOne uses objects of ClassTwo.
Question
Which of the following represents a good strategy regarding cohesion and coupling?

A) Maximize cohesion and remove unnecessary coupling.
B) Minimize cohesion and remove unnecessary coupling..
C) Maximize both cohesion and coupling.
D) Minimize cohesion and maximize coupling..
Question
Which of the following most likely indicates that you have chosen a good name for your class?

A) The name consists of a single word.
B) You can tell by the name what an object of the class is supposed to represent.
C) You can easily determine by the name how many concepts the class represents.
D) The name describes what task the class will perform.
Question
Which class category has static methods and constants, but no objects?

A) Real-life entity abstraction
B) Actor class
C) Utility class
D) Concept class
Question
Why is it generally considered good practice to minimize coupling between classes?

A) Low coupling increases the operational efficiency of a program.
B) High coupling implies less interface cohesion.
C) High coupling increases program maintenance and hinders code reuse.
D) Low coupling decreases the probability of code redundancy.
Question
Which of the following describes an immutable class?

A) A class that has no accessor or mutator methods.
B) A class that has no accessor methods, but does have mutator methods.
C) A class that has accessor methods, but does not have mutator methods.
D) A class that has both accessor and mutator methods.
Question
Which of the following describes the first thing you should do when beginning a new object-oriented programming activity?

A) Consider how many concepts each class should represent.
B) Determine which categories of classes may be needed for the project.
C) Decide what combination of functions and methods are appropriate for the project.
D) Identify the objects and the classes to which they belong.
Question
Why does the Scanner class belong to the category of classes known as actors?

A) It acts as an interface between your program and the command line.
B) It serves as an abstract entity that represents a user of your program.
C) It plays an important part in streamlining the operation of your system.
D) It performs a task, such as scanning a stream for numbers and characters.
Question
Which of the following is a good indicator that a class is overreaching and trying to accomplish too much?

A) The class has more constants than methods
B) The public interface refers to multiple concepts
C) The public interface exposes private features
D) The class is both cohesive and dependent.
Question
Which of the following is considered by the text to be the most important consideration when designing a class?

A) Each class should represent an appropriate mathematical concept.
B) Each class should represent a single concept or object from the problem domain.
C) Each class should represent no more than three specific concepts.
D) Each class should represent multiple concepts only if they are closely related.
Question
A class named CurrencyTranslator would most probably fall into which of the following class categories?

A) Actor classes
B) Starter classes
C) Abstract entities
D) Utility classes
Question
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
Question
Which of the following would be an appropriate name for a game-related class?

A) CompletedLevelOne
B) InitialLevel
C) ResetCurrentLevel
D) AscendToFinalLevel
Question
Which of the following is a true statement regarding consistency in coding?

A) Inconsistencies nearly always produce fatal flaws.
B) Inconsistencies are an annoyance, because they can be so easily avoided.
C) Consistency is not important in programming.
D) Consistency always requires extra coding.
Question
Which of the following questions should you ask yourself in order to determine if you have named your class properly?

A) Does the class name contain 8 or fewer characters?
B) Is the class name a verb?
C) Can I visualize an object of the class?
D) Does the class name describe the tasks that this class will accomplish?
Question
Judging by the name of the method, which of the following methods would most likely be a mutator method?

A) getListOfDeposits.
B) printAccountBalance.
C) isOverdrawn.
D) Deposit.
Question
Consider the method in the following code snippet: public void getRewardPoints()
{
System.out.println("Your Reward Points balance is now " + pointBalance);
}
Which of the following statements would not be a valid criticism of the design of this method?

A) It violates the design rule of minimizing the coupling of classes.
B) It assumes that the message will always need to be in English.
C) It might not work in an embedded system.
D) It should not be a separate method since it is only one line long.
Question
In Java, which of the following mechanisms describe the copying of an object reference into a parameter variable?

A) Call-by-reference .
B) Call-by-value.
C) Call-by-precondition.
D) Call-by-object.
Question
Which of the following can potentially be changed by a Java method?

A) An object reference parameter.
B) The state of an object reference parameter's attribute.
C) A primitive parameter.
D) A String parameter.
Question
Why can't Java methods change parameters of primitive type?

A) Java methods can have no actual impact on parameters of any type.
B) Parameters of primitive type are considered by Java methods to be local variables.
C) Parameters of primitive type are immutable.
D) Java methods cannot accept parameters of primitive type.
Question
Which of the following classifications of method behavior produces acceptable side effects?

A) Accessor methods that do not change explicit parameters.
B) Mutator methods that do not change explicit parameters.
C) Any method that changes an explicit parameter.
D) Any method that changes another object.
Question
Which of the following is true regarding side effects of methods?

A) Modification of implicit parameters should be restricted to primitive data types.
B) Modification of explicit parameters should never be allowed.
C) Side effects involving standard output should be limited to String data.
D) Minimize side effects that go beyond modification of implicit parameters.
Question
Which of the following types of side effects potentially violates the rule of minimizing the coupling of classes?

A) Standard output.
B) Modification of implicit parameters.
C) Modification of explicit parameters.
D) Modification of both implicit and explicit parameters.
Question
A class that has only accessor methods and no mutators methods is called a/an ____ class.

A) Utility.
B) Static.
C) Immutable.
D) Actor.
Question
Which of the following statements is true relative to classes that will successfully compile?

A) They must have both mutator and accessor methods.
B) They must have accessors, and optionally may have mutators.
C) They must have mutators, and optionally may have accessors.
D) They may have either mutator or accessor methods, or both.
Question
Side effects related to standard output generally violate which of the following rules?

A) Never display the values of explicit parameters.
B) Never display the values of implicit parameters.
C) Minimize the coupling of classes.
D) Maximize the coupling of classes.
Question
Given the following method header, other would be classified as which of the following parameter types? public void transfer(double amount, BankAccount other)

A) Implicit parameter.
B) Explicit parameter.
C) Global parameter.
D) Mutable parameter.
Question
Which of the following is an example of an immutable class?

A) Math.
B) Scanner.
C) String.
D) System.
Question
Which of the following is true regarding objects created from immutable classes?

A) It is safe to give out references to immutable class objects freely.
B) An immutable object can only be modified by its mutator method.
C) It is not advisable to return immutable object references from accessor methods.
D) Immutable classes do not have constructors.
Question
Which of the following statements describes a precondition?

A) A logical condition in a program that you believe to be true.
B) A guarantee that the object is in a certain state after the method call is completed.
C) A requirement that the caller of a method must meet.
D) A set of criteria defined by the caller of a method.
Question
Which of the following statements is true regarding method parameters in Java?

A) All method parameters use the call-by-value mechanism.
B) Only method parameters of primitive type use the call-by-value mechanism.
C) All method parameters use the call-by-reference mechanism.
D) Only method parameters of object type use the call-by-value mechanism.
Question
Mutator methods exhibit which of the following types of side effect?

A) Modification of the implicit parameter.
B) Modification of an explicit parameter.
C) Production of printed output.
D) Acceptance of text input.
Question
Which of the following classifications of method behavior is accurate?

A) Methods that do not change explicit parameters always have side effects.
B) Methods that change explicit parameters do not have side effects.
C) Methods that change explicit parameters always have side effects.
D) Methods that do not change explicit parameters never have side effects.
Question
Which of the following statements describes one aspect of a postcondition?

A) A logical condition in a program that you believe to be true.
B) A guarantee that the object is in a certain state after the method call is completed.
C) A requirement that the caller of a method must meet.
D) A set of criteria defined by the caller of a method.
Question
Which of the following does NOT describe a particular side effect related to standard output?

A) Messages printed in a particular language may be of limited usefulness.
B) Methods that rely on standard output have limited usefulness in embedded systems.
C) Programmers may be surprised by unexpected method actions.
D) Programmers may need values for purposes other than informational messages.
Question
Which of the following statements is generally true regarding static methods and variables?

A) The use of static variables and methods should be minimized.
B) The use of static variables and methods should be maximized.
C) A lot of static methods and variables indicate a well-designed object-oriented system.
D) Always choose static methods and variables over similar object-based implementations.
Question
Which of the following statements regarding static methods is true?

A) The textbook recommends that you minimize the use of static methods.
B) The textbook recommends that static methods should be liberally used within classes.
C) Use of static methods usually leads to good object-oriented design.
D) Static methods can be easily evolved to add more functionality.
Question
An AssertionError will be generated under which of the following conditions?

A) Assertion checking is turned off.
B) Assertion checking is turned off and an assertion fails.
C) An assertion fails and assertion checking is turned on.
D) Any time an assertion fails.
Question
The use of the static keyword in a method declaration implies which of the following?

A) The method can only operate on immutable objects.
B) The method can only be called from within the main method.
C) The method cannot be overloaded.
D) The method can have only explicit parameters.
Question
Which of the following types of methods are invoked on objects?

A) Static method.
B) Class method.
C) Instance method.
D) Either static or instance methods.
Question
Consider the partial Date class below which represents a day of the year. public class Date
{
Private int month; // A value between 1 and 12
Private int day; // A value between 1 and the last day
// of the month
Public int getMonth() { return month; }
Public void setMonth(int newMonth)
{
If (newMonth >= 1 && newMonth <= 12) { month = newMonth; }
}
Public int getDay() { return day; }
Private int lastDayOfMonth()
{
Switch (month)
{
Case 9: case 4: case 6: case 11:
Return 30;
Case 2: return 28;
Default: return 31;
}
}
}
What type of method is setMonth?

A) mutator
B) accessor
C) constructor
Question
It has been suggested the accessor method below be added to the class to return the Date one day later than the given date. public Date getNextDate()
{
If (day == lastDayOfMonth())
{
Month++;
If (month == 12) { month = 1; }
Day = 1;
}
Else { day++; }
Return this;
}
What is wrong with this design?

A) You cannot return this from a method.
B) It uses lastDayOfMonth, a private method of the class.
C) It has the side effect of changing the Date.
D) Since it returns a Date other than this one, the class is not consistent.
Question
Consider the method signature in the following code snippet: public static double getTriangleArea (double heightLen, double baseLen)
Which of the following would be a valid postcondition for this method?

A) Postcondition: getTriangleArea() >= 0
B) Postcondition: getTriangleArea() > 0
C) Postcondition: getTriangleArea() <= baseLen
D) There are no valid postcoditions that could be specified for this method
Question
Where in a class should static variables be declared and initialized?

A) Inside the constructor method.
B) Inside the class, but outside of any method body.
C) Outside the class - in a separate designated static class.
D) Outside the class, but inside the same physical file.
Question
Which command would execute a program with assertion checking turned on?

A) java -assertionson MainClass
B) java -assertionsenabled MainClass
C) java -enableassert MainClass
D) java -enableassertions MainClass
Question
Which of the following statements is true regarding the precondition of a method?

A) It is a suggestion to the caller of the method regarding method input values.
B) It guarantees the object will be in a certain state after the method call is completed.
C) It limits the potential data type of the parameter variables.
D) If it is not met, the method is not responsible for computing the correct result.
Question
Which of the following statements describes an assertion?

A) A logical condition in a program that you believe to be true.
B) A guarantee that the object is in a certain state after the method call is completed.
C) A requirement that the caller of a method must meet.
D) A set of criteria defined by the caller of a method.
Question
In which of the following cases could a static variable be declared as something other than private?

A) When it will be accessed by multiple objects.
B) When implementing static constants.
C) When declared inside a private method.
D) Static variables should never be declared as anything but private.
Question
Consider the partial Date class below which represents a day of the year. public class Date
{
Private int month; // A value between 1 and 12
Private int day; // A value between 1 and the last day
// of the month
Public int getMonth() { return month; }
Public void setMonth(int newMonth)
{
If (newMonth >= 1 && newMonth <= 12) { month = newMonth; }
}
Public int getDay() { return day; }
Private int lastDayOfMonth()
{
Switch (month)
{
Case 9: case 4: case 6: case 11:
Return 30;
Case 2: return 28;
Default: return 31;
}
}
}
What type of method is getMonth?

A) mutator
B) constructor
C) accessor
Question
Which perspective should be used in formulating pre- and postconditions?

A) The private implementation of the class.
B) The public interface of the class.
C) The knowledge of the designer.
D) The requirements of the user.
Question
A static method can have which of the following types of parameters?

A) Only implicit parameters.
B) Only explicit parameters.
C) Both implicit and explicit parameters.
D) A static method cannot have parameters.
Question
Why is a static variable also referred to as a class variable?

A) There is a single copy available to all objects of the class.
B) It is encapsulated within the class.
C) Each class has one and only one static variable.
D) It is stored in the separate class area of each object.
Question
Which of the following constitutes a common reason for creating a static method?

A) To encapsulate a computation that involves only numbers.
B) To implement a computation that only involves implicit parameters.
C) To test a computation prior to implementing it in a class.
D) To improve efficiency by reducing overhead associated with the use of objects.
Question
Pre- and postconditions may be viewed as a contract between which of the following parties?

A) A method and its caller.
B) A class and its interface.
C) A method signature and its implementation.
D) An object and its class.
Question
Which of the following classes has a static variable that is commonly used when communicating with standard output?

A) Scanner.
B) String.
C) System.
D) Object.
Question
Consider the following code snippet: public class Vehicle
{
String vehicleType;
) . .
}
Which of the following statements about the variable vehicleType is true?

A) It can be accessed by all classes in the same package as the Vehicle class.
B) It can be accessed only by code within the Vehicle class.
C) It can be accessed only by public methods declared within the Vehicle class.
D) It can be accessed only by private methods declared within the Vehicle class.
Question
A new class is proposed to collect information about a group of DVDs. Which of the following is the best name for this class?

A) DVDCollection
B) DVD
C) StoreDVDInformation
D) Collection
Question
A new class is proposed to collect information about a group of DVDs. A separate class containing information about a single DVD, named DVD, has already been created. Which of the following is the best design to store the data and size of this collection?

A) Have an ArrayList of DVDs and use its size as the size of the collection.
B) Have an ArrayList of DVDs and an integer representing the number of DVDs in the collection.
C) Have an array of DVDs and use its size as the size of the collection.
D) Have a single DVD variable representing the last DVD added and an integer representing the number of DVDs in the collection.
Question
A new method, getMonthName, to get the name of the Date's month ("January", February", etc.) is to be added to the class Date. How will the instance variables need to be changed to handle this new method?

A) The type of the month instance variable will need to be changed to String.
B) A new String variable called monthName will need to be added to the class.
C) A new class called MonthNameAndNumber will need to be created to store both the name and number of the month and the type of the instance variable month will need to be changed to MonthNameAndNumber.
D) No change is needed.
Question
A new class is proposed to collect information about a group of DVDs. Which of the following is the best structure for this class?

A) Have separate classes for a single DVD and the entire DVD collection.
B) Have one class to store information about DVDs and the collection named DVDsInformation
C) Have one class to store information about the collection name and send information about the DVDs as simple data (integers, Strings, etc.)
D) Have one class to store information about a single DVD and just use an ArrayList to store the collection.
Question
A new method, getMonthName, to get the name of the Date's month ("January", February", etc.) is to be added to the class Date. Which of the following headers should it have?

A) public String getMonthName(int month)
B) public String getMonthName()
C) public void getMonthName(String monthName)
D) public void getMonthName(int month, String monthName)
Question
When are statements in a class-level initialization block executed?

A) Before the code in the class constructor is executed.
B) Once when the class is loaded.
C) Whenever objects of the class are used to access methods.
D) After the code in the class constructor is executed.
Question
Can the method lastDayOfMonth be changed to be a static method by just changing the header to the following? private static int lastDayOfMonth()

A) No. It could no longer access the month instance variable.
B) No. A class cannot have both static and non-static methods.
C) Yes. No other change is necessary.
D) Yes, but it must be changed to public as well.
Question
To use a public variable or method outside of its class, you must ____ the name.

A) bind
B) encapsulate
C) instantiate
D) qualify
Question
Which of the following statements describes the scope of a local variable?

A) From the beginning through the end of the block that encloses it.
B) From the point of its declaration to the point where it is set to null.
C) From the point of its initialization to the end of the block that encloses it.
D) From the point of its declaration to the end of the block that encloses it.
Question
Under which of the following conditions must you qualify the name of a public class member?

A) If it is to be used outside its class.
B) If it is to be used inside its class.
C) Public class members must always be qualified.
D) Public class members never need to be qualified.
Question
Which of the following statements generally describes the scope of a variable?

A) The ability of a variable to access other variables in the same program.
B) The amount of data in bytes that the variable can contain.
C) The range of data types that the variable can legally be cast into.
D) The region of a program in which the variable can be accessed.
Question
Consider the following code snippet: public class RewardPointsAccount
{
Private int currentRewardPointBalance;
Private int level1Cutoff = 15000;
Public static void main (String [] args)
{
Int level1Cutoff = 15000;
If (blnEliteCustomer)
{
This.Level1Cutoff = 12500;
) . .
}
}
Which of the following statements is true?

A) It is illegal to declare the level1Cutoff variable within the main method
B) The code within the main method changes the value of the instance variable level1Cutoff for elite customers
C) The level1Cutoff variable within the main method does not change the level1Cutoff instance variable for elite customers
D) The level1Cutoff class variable shadows the level1Cutoff variable within the main method
Question
What will have to change if the instance variables month and day of the Date class are replaced by the single instance integer variable dayOfTheYear?

A) The implementation of the methods will change, but the interface will not need to change.
B) The implementation of getDay will not change, but the implementations of the other methods will not change and the interface will not change.
C) The interface will need to change to remove setMonth, but no other parts of the interface will change.
D) All of the interface will need to be changed when the instance variables change.
Question
What is the scope of a private instance variable?

A) The entire class in which the variable is defined.
B) All classes in the same package as the class in which the variable is defined.
C) The entire program.
D) Only the method in which the variable is defined.
Question
Consider the following code snippet: public class RewardPointsAccount
{
Private int currentRewardPointBalance;
Private static int level1Cutoff = 15000;
)..
}
If a program instantiates four objects using this class, which of the following statements will be true?

A) Each object will have a currentRewardPointBalance instance variable and a level1Cutoff instance variable.
B) All objects will share a single currentRewardPointBalance class variable and a level1Cutoff class variable.
C) Each object will have a currentRewardPointBalance instance variable, but all objects will share a level1Cutoff class variable.
D) All objects will share a currentRewardPointBalance class variable and each object will have a level1Cutoff instance variable.
Question
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.
Question
Under which of the following conditions can you have local variables with identical names?

A) If their scopes are nested.
B) If they are of different data types.
C) If their scopes do not overlap.
D) If they both reference the same object.
Question
Which of the following names would be considered to be qualified?

A) studentOne.getGraduationYear()
B) this.getGraduationYear()
C) getGraduationYear()
D) getGraduationYear().print()
Question
When are statements in a class-level static initialization block executed?

A) Before the code in the class constructor is executed.
B) Once when the class is loaded.
C) Whenever objects of the class are used to access methods.
D) After the code in the class constructor is executed.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/95
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 8: Designing Classes
1
A UML class diagram would be most useful in visually illustrating which of the following?

A) the cohesiveness of a class's interface.
B) the amount of complexity of a class's interface.
C) dependencies between classes.
D) relationships between classes and their interfaces.
C
2
The String class is an example of which of the following types of classes?

A) Static class.
B) Immutable class.
C) Abstract class.
D) Mutable class.
B
3
General Java variable naming conventions would suggest that a variable named NICKEL_VALUE would most probably be declared using which of the following combinations of modifiers?

A) public void final
B) public static final double
C) private static double
D) private static
B
4
Under which of the following conditions would the public interface of a class be considered cohesive?

A) All of its features are public and none of its features are static.
B) The quality of the public interface is rated as moderate to high.
C) All of its features are related to the concept that the class represents.
D) It is obvious that the public interface refers to multiple concepts.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
5
Which type of method modifies the object on which it is invoked?

A) Constructor method.
B) Static method.
C) Accessor method.
D) Mutator method.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
6
A class (ClassOne) is considered to have a dependency on another class (ClassTwo) under which of the following conditions?

A) Each class uses objects of the other.
B) The public interfaces of both classes are cohesive.
C) ClassTwo uses objects of ClassOne.
D) ClassOne uses objects of ClassTwo.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
7
Which of the following represents a good strategy regarding cohesion and coupling?

A) Maximize cohesion and remove unnecessary coupling.
B) Minimize cohesion and remove unnecessary coupling..
C) Maximize both cohesion and coupling.
D) Minimize cohesion and maximize coupling..
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
8
Which of the following most likely indicates that you have chosen a good name for your class?

A) The name consists of a single word.
B) You can tell by the name what an object of the class is supposed to represent.
C) You can easily determine by the name how many concepts the class represents.
D) The name describes what task the class will perform.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
9
Which class category has static methods and constants, but no objects?

A) Real-life entity abstraction
B) Actor class
C) Utility class
D) Concept class
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
10
Why is it generally considered good practice to minimize coupling between classes?

A) Low coupling increases the operational efficiency of a program.
B) High coupling implies less interface cohesion.
C) High coupling increases program maintenance and hinders code reuse.
D) Low coupling decreases the probability of code redundancy.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
11
Which of the following describes an immutable class?

A) A class that has no accessor or mutator methods.
B) A class that has no accessor methods, but does have mutator methods.
C) A class that has accessor methods, but does not have mutator methods.
D) A class that has both accessor and mutator methods.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
12
Which of the following describes the first thing you should do when beginning a new object-oriented programming activity?

A) Consider how many concepts each class should represent.
B) Determine which categories of classes may be needed for the project.
C) Decide what combination of functions and methods are appropriate for the project.
D) Identify the objects and the classes to which they belong.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
13
Why does the Scanner class belong to the category of classes known as actors?

A) It acts as an interface between your program and the command line.
B) It serves as an abstract entity that represents a user of your program.
C) It plays an important part in streamlining the operation of your system.
D) It performs a task, such as scanning a stream for numbers and characters.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
14
Which of the following is a good indicator that a class is overreaching and trying to accomplish too much?

A) The class has more constants than methods
B) The public interface refers to multiple concepts
C) The public interface exposes private features
D) The class is both cohesive and dependent.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
15
Which of the following is considered by the text to be the most important consideration when designing a class?

A) Each class should represent an appropriate mathematical concept.
B) Each class should represent a single concept or object from the problem domain.
C) Each class should represent no more than three specific concepts.
D) Each class should represent multiple concepts only if they are closely related.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
16
A class named CurrencyTranslator would most probably fall into which of the following class categories?

A) Actor classes
B) Starter classes
C) Abstract entities
D) Utility classes
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
17
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
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
18
Which of the following would be an appropriate name for a game-related class?

A) CompletedLevelOne
B) InitialLevel
C) ResetCurrentLevel
D) AscendToFinalLevel
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
19
Which of the following is a true statement regarding consistency in coding?

A) Inconsistencies nearly always produce fatal flaws.
B) Inconsistencies are an annoyance, because they can be so easily avoided.
C) Consistency is not important in programming.
D) Consistency always requires extra coding.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
20
Which of the following questions should you ask yourself in order to determine if you have named your class properly?

A) Does the class name contain 8 or fewer characters?
B) Is the class name a verb?
C) Can I visualize an object of the class?
D) Does the class name describe the tasks that this class will accomplish?
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
21
Judging by the name of the method, which of the following methods would most likely be a mutator method?

A) getListOfDeposits.
B) printAccountBalance.
C) isOverdrawn.
D) Deposit.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
22
Consider the method in the following code snippet: public void getRewardPoints()
{
System.out.println("Your Reward Points balance is now " + pointBalance);
}
Which of the following statements would not be a valid criticism of the design of this method?

A) It violates the design rule of minimizing the coupling of classes.
B) It assumes that the message will always need to be in English.
C) It might not work in an embedded system.
D) It should not be a separate method since it is only one line long.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
23
In Java, which of the following mechanisms describe the copying of an object reference into a parameter variable?

A) Call-by-reference .
B) Call-by-value.
C) Call-by-precondition.
D) Call-by-object.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
24
Which of the following can potentially be changed by a Java method?

A) An object reference parameter.
B) The state of an object reference parameter's attribute.
C) A primitive parameter.
D) A String parameter.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
25
Why can't Java methods change parameters of primitive type?

A) Java methods can have no actual impact on parameters of any type.
B) Parameters of primitive type are considered by Java methods to be local variables.
C) Parameters of primitive type are immutable.
D) Java methods cannot accept parameters of primitive type.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
26
Which of the following classifications of method behavior produces acceptable side effects?

A) Accessor methods that do not change explicit parameters.
B) Mutator methods that do not change explicit parameters.
C) Any method that changes an explicit parameter.
D) Any method that changes another object.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
27
Which of the following is true regarding side effects of methods?

A) Modification of implicit parameters should be restricted to primitive data types.
B) Modification of explicit parameters should never be allowed.
C) Side effects involving standard output should be limited to String data.
D) Minimize side effects that go beyond modification of implicit parameters.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
28
Which of the following types of side effects potentially violates the rule of minimizing the coupling of classes?

A) Standard output.
B) Modification of implicit parameters.
C) Modification of explicit parameters.
D) Modification of both implicit and explicit parameters.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
29
A class that has only accessor methods and no mutators methods is called a/an ____ class.

A) Utility.
B) Static.
C) Immutable.
D) Actor.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
30
Which of the following statements is true relative to classes that will successfully compile?

A) They must have both mutator and accessor methods.
B) They must have accessors, and optionally may have mutators.
C) They must have mutators, and optionally may have accessors.
D) They may have either mutator or accessor methods, or both.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
31
Side effects related to standard output generally violate which of the following rules?

A) Never display the values of explicit parameters.
B) Never display the values of implicit parameters.
C) Minimize the coupling of classes.
D) Maximize the coupling of classes.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
32
Given the following method header, other would be classified as which of the following parameter types? public void transfer(double amount, BankAccount other)

A) Implicit parameter.
B) Explicit parameter.
C) Global parameter.
D) Mutable parameter.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
33
Which of the following is an example of an immutable class?

A) Math.
B) Scanner.
C) String.
D) System.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
34
Which of the following is true regarding objects created from immutable classes?

A) It is safe to give out references to immutable class objects freely.
B) An immutable object can only be modified by its mutator method.
C) It is not advisable to return immutable object references from accessor methods.
D) Immutable classes do not have constructors.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
35
Which of the following statements describes a precondition?

A) A logical condition in a program that you believe to be true.
B) A guarantee that the object is in a certain state after the method call is completed.
C) A requirement that the caller of a method must meet.
D) A set of criteria defined by the caller of a method.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
36
Which of the following statements is true regarding method parameters in Java?

A) All method parameters use the call-by-value mechanism.
B) Only method parameters of primitive type use the call-by-value mechanism.
C) All method parameters use the call-by-reference mechanism.
D) Only method parameters of object type use the call-by-value mechanism.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
37
Mutator methods exhibit which of the following types of side effect?

A) Modification of the implicit parameter.
B) Modification of an explicit parameter.
C) Production of printed output.
D) Acceptance of text input.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
38
Which of the following classifications of method behavior is accurate?

A) Methods that do not change explicit parameters always have side effects.
B) Methods that change explicit parameters do not have side effects.
C) Methods that change explicit parameters always have side effects.
D) Methods that do not change explicit parameters never have side effects.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
39
Which of the following statements describes one aspect of a postcondition?

A) A logical condition in a program that you believe to be true.
B) A guarantee that the object is in a certain state after the method call is completed.
C) A requirement that the caller of a method must meet.
D) A set of criteria defined by the caller of a method.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
40
Which of the following does NOT describe a particular side effect related to standard output?

A) Messages printed in a particular language may be of limited usefulness.
B) Methods that rely on standard output have limited usefulness in embedded systems.
C) Programmers may be surprised by unexpected method actions.
D) Programmers may need values for purposes other than informational messages.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
41
Which of the following statements is generally true regarding static methods and variables?

A) The use of static variables and methods should be minimized.
B) The use of static variables and methods should be maximized.
C) A lot of static methods and variables indicate a well-designed object-oriented system.
D) Always choose static methods and variables over similar object-based implementations.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
42
Which of the following statements regarding static methods is true?

A) The textbook recommends that you minimize the use of static methods.
B) The textbook recommends that static methods should be liberally used within classes.
C) Use of static methods usually leads to good object-oriented design.
D) Static methods can be easily evolved to add more functionality.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
43
An AssertionError will be generated under which of the following conditions?

A) Assertion checking is turned off.
B) Assertion checking is turned off and an assertion fails.
C) An assertion fails and assertion checking is turned on.
D) Any time an assertion fails.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
44
The use of the static keyword in a method declaration implies which of the following?

A) The method can only operate on immutable objects.
B) The method can only be called from within the main method.
C) The method cannot be overloaded.
D) The method can have only explicit parameters.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
45
Which of the following types of methods are invoked on objects?

A) Static method.
B) Class method.
C) Instance method.
D) Either static or instance methods.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
46
Consider the partial Date class below which represents a day of the year. public class Date
{
Private int month; // A value between 1 and 12
Private int day; // A value between 1 and the last day
// of the month
Public int getMonth() { return month; }
Public void setMonth(int newMonth)
{
If (newMonth >= 1 && newMonth <= 12) { month = newMonth; }
}
Public int getDay() { return day; }
Private int lastDayOfMonth()
{
Switch (month)
{
Case 9: case 4: case 6: case 11:
Return 30;
Case 2: return 28;
Default: return 31;
}
}
}
What type of method is setMonth?

A) mutator
B) accessor
C) constructor
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
47
It has been suggested the accessor method below be added to the class to return the Date one day later than the given date. public Date getNextDate()
{
If (day == lastDayOfMonth())
{
Month++;
If (month == 12) { month = 1; }
Day = 1;
}
Else { day++; }
Return this;
}
What is wrong with this design?

A) You cannot return this from a method.
B) It uses lastDayOfMonth, a private method of the class.
C) It has the side effect of changing the Date.
D) Since it returns a Date other than this one, the class is not consistent.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
48
Consider the method signature in the following code snippet: public static double getTriangleArea (double heightLen, double baseLen)
Which of the following would be a valid postcondition for this method?

A) Postcondition: getTriangleArea() >= 0
B) Postcondition: getTriangleArea() > 0
C) Postcondition: getTriangleArea() <= baseLen
D) There are no valid postcoditions that could be specified for this method
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
49
Where in a class should static variables be declared and initialized?

A) Inside the constructor method.
B) Inside the class, but outside of any method body.
C) Outside the class - in a separate designated static class.
D) Outside the class, but inside the same physical file.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
50
Which command would execute a program with assertion checking turned on?

A) java -assertionson MainClass
B) java -assertionsenabled MainClass
C) java -enableassert MainClass
D) java -enableassertions MainClass
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
51
Which of the following statements is true regarding the precondition of a method?

A) It is a suggestion to the caller of the method regarding method input values.
B) It guarantees the object will be in a certain state after the method call is completed.
C) It limits the potential data type of the parameter variables.
D) If it is not met, the method is not responsible for computing the correct result.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
52
Which of the following statements describes an assertion?

A) A logical condition in a program that you believe to be true.
B) A guarantee that the object is in a certain state after the method call is completed.
C) A requirement that the caller of a method must meet.
D) A set of criteria defined by the caller of a method.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
53
In which of the following cases could a static variable be declared as something other than private?

A) When it will be accessed by multiple objects.
B) When implementing static constants.
C) When declared inside a private method.
D) Static variables should never be declared as anything but private.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
54
Consider the partial Date class below which represents a day of the year. public class Date
{
Private int month; // A value between 1 and 12
Private int day; // A value between 1 and the last day
// of the month
Public int getMonth() { return month; }
Public void setMonth(int newMonth)
{
If (newMonth >= 1 && newMonth <= 12) { month = newMonth; }
}
Public int getDay() { return day; }
Private int lastDayOfMonth()
{
Switch (month)
{
Case 9: case 4: case 6: case 11:
Return 30;
Case 2: return 28;
Default: return 31;
}
}
}
What type of method is getMonth?

A) mutator
B) constructor
C) accessor
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
55
Which perspective should be used in formulating pre- and postconditions?

A) The private implementation of the class.
B) The public interface of the class.
C) The knowledge of the designer.
D) The requirements of the user.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
56
A static method can have which of the following types of parameters?

A) Only implicit parameters.
B) Only explicit parameters.
C) Both implicit and explicit parameters.
D) A static method cannot have parameters.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
57
Why is a static variable also referred to as a class variable?

A) There is a single copy available to all objects of the class.
B) It is encapsulated within the class.
C) Each class has one and only one static variable.
D) It is stored in the separate class area of each object.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
58
Which of the following constitutes a common reason for creating a static method?

A) To encapsulate a computation that involves only numbers.
B) To implement a computation that only involves implicit parameters.
C) To test a computation prior to implementing it in a class.
D) To improve efficiency by reducing overhead associated with the use of objects.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
59
Pre- and postconditions may be viewed as a contract between which of the following parties?

A) A method and its caller.
B) A class and its interface.
C) A method signature and its implementation.
D) An object and its class.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
60
Which of the following classes has a static variable that is commonly used when communicating with standard output?

A) Scanner.
B) String.
C) System.
D) Object.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
61
Consider the following code snippet: public class Vehicle
{
String vehicleType;
) . .
}
Which of the following statements about the variable vehicleType is true?

A) It can be accessed by all classes in the same package as the Vehicle class.
B) It can be accessed only by code within the Vehicle class.
C) It can be accessed only by public methods declared within the Vehicle class.
D) It can be accessed only by private methods declared within the Vehicle class.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
62
A new class is proposed to collect information about a group of DVDs. Which of the following is the best name for this class?

A) DVDCollection
B) DVD
C) StoreDVDInformation
D) Collection
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
63
A new class is proposed to collect information about a group of DVDs. A separate class containing information about a single DVD, named DVD, has already been created. Which of the following is the best design to store the data and size of this collection?

A) Have an ArrayList of DVDs and use its size as the size of the collection.
B) Have an ArrayList of DVDs and an integer representing the number of DVDs in the collection.
C) Have an array of DVDs and use its size as the size of the collection.
D) Have a single DVD variable representing the last DVD added and an integer representing the number of DVDs in the collection.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
64
A new method, getMonthName, to get the name of the Date's month ("January", February", etc.) is to be added to the class Date. How will the instance variables need to be changed to handle this new method?

A) The type of the month instance variable will need to be changed to String.
B) A new String variable called monthName will need to be added to the class.
C) A new class called MonthNameAndNumber will need to be created to store both the name and number of the month and the type of the instance variable month will need to be changed to MonthNameAndNumber.
D) No change is needed.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
65
A new class is proposed to collect information about a group of DVDs. Which of the following is the best structure for this class?

A) Have separate classes for a single DVD and the entire DVD collection.
B) Have one class to store information about DVDs and the collection named DVDsInformation
C) Have one class to store information about the collection name and send information about the DVDs as simple data (integers, Strings, etc.)
D) Have one class to store information about a single DVD and just use an ArrayList to store the collection.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
66
A new method, getMonthName, to get the name of the Date's month ("January", February", etc.) is to be added to the class Date. Which of the following headers should it have?

A) public String getMonthName(int month)
B) public String getMonthName()
C) public void getMonthName(String monthName)
D) public void getMonthName(int month, String monthName)
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
67
When are statements in a class-level initialization block executed?

A) Before the code in the class constructor is executed.
B) Once when the class is loaded.
C) Whenever objects of the class are used to access methods.
D) After the code in the class constructor is executed.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
68
Can the method lastDayOfMonth be changed to be a static method by just changing the header to the following? private static int lastDayOfMonth()

A) No. It could no longer access the month instance variable.
B) No. A class cannot have both static and non-static methods.
C) Yes. No other change is necessary.
D) Yes, but it must be changed to public as well.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
69
To use a public variable or method outside of its class, you must ____ the name.

A) bind
B) encapsulate
C) instantiate
D) qualify
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
70
Which of the following statements describes the scope of a local variable?

A) From the beginning through the end of the block that encloses it.
B) From the point of its declaration to the point where it is set to null.
C) From the point of its initialization to the end of the block that encloses it.
D) From the point of its declaration to the end of the block that encloses it.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
71
Under which of the following conditions must you qualify the name of a public class member?

A) If it is to be used outside its class.
B) If it is to be used inside its class.
C) Public class members must always be qualified.
D) Public class members never need to be qualified.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
72
Which of the following statements generally describes the scope of a variable?

A) The ability of a variable to access other variables in the same program.
B) The amount of data in bytes that the variable can contain.
C) The range of data types that the variable can legally be cast into.
D) The region of a program in which the variable can be accessed.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
73
Consider the following code snippet: public class RewardPointsAccount
{
Private int currentRewardPointBalance;
Private int level1Cutoff = 15000;
Public static void main (String [] args)
{
Int level1Cutoff = 15000;
If (blnEliteCustomer)
{
This.Level1Cutoff = 12500;
) . .
}
}
Which of the following statements is true?

A) It is illegal to declare the level1Cutoff variable within the main method
B) The code within the main method changes the value of the instance variable level1Cutoff for elite customers
C) The level1Cutoff variable within the main method does not change the level1Cutoff instance variable for elite customers
D) The level1Cutoff class variable shadows the level1Cutoff variable within the main method
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
74
What will have to change if the instance variables month and day of the Date class are replaced by the single instance integer variable dayOfTheYear?

A) The implementation of the methods will change, but the interface will not need to change.
B) The implementation of getDay will not change, but the implementations of the other methods will not change and the interface will not change.
C) The interface will need to change to remove setMonth, but no other parts of the interface will change.
D) All of the interface will need to be changed when the instance variables change.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
75
What is the scope of a private instance variable?

A) The entire class in which the variable is defined.
B) All classes in the same package as the class in which the variable is defined.
C) The entire program.
D) Only the method in which the variable is defined.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
76
Consider the following code snippet: public class RewardPointsAccount
{
Private int currentRewardPointBalance;
Private static int level1Cutoff = 15000;
)..
}
If a program instantiates four objects using this class, which of the following statements will be true?

A) Each object will have a currentRewardPointBalance instance variable and a level1Cutoff instance variable.
B) All objects will share a single currentRewardPointBalance class variable and a level1Cutoff class variable.
C) Each object will have a currentRewardPointBalance instance variable, but all objects will share a level1Cutoff class variable.
D) All objects will share a currentRewardPointBalance class variable and each object will have a level1Cutoff instance variable.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
77
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.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
78
Under which of the following conditions can you have local variables with identical names?

A) If their scopes are nested.
B) If they are of different data types.
C) If their scopes do not overlap.
D) If they both reference the same object.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
79
Which of the following names would be considered to be qualified?

A) studentOne.getGraduationYear()
B) this.getGraduationYear()
C) getGraduationYear()
D) getGraduationYear().print()
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
80
When are statements in a class-level static initialization block executed?

A) Before the code in the class constructor is executed.
B) Once when the class is loaded.
C) Whenever objects of the class are used to access methods.
D) After the code in the class constructor is executed.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 95 flashcards in this deck.