Full Test Bank Writing Classes Chase Chapter 5 - Java Foundations 4th Edition | Test Bank with Answer Key by John Lewis by John Lewis, Peter DePasquale, Joe Chase. DOCX document preview.
Chapter 5: Writing Classes
Multiple Choice Questions:
1) A ________________ diagram helps us visualize the contents of and relationships among the classes of a program.
a) class and object
b) UML
c) object-oriented
d) public
e) private
2) Regression testing refers to
a) re-testing a program after fixing a problem to ensure that the fix worked and that it did not introduce another problem.
b) executing the statements in the program in reverse order.
c) executing the program on many different types of computers and comparing the results.
d) running a program with many different sets of inputs.
e) None of these describes regression testing
3) When applied to instance variables, the ________________ visibility modifier enforces encapsulation.
a) static
b) final
c) public
d) private
e) none of the above
4) Which of the following types of methods do not have any return type (not even a void return type)?
a) methods declared as static
b) methods declared as public
c) methods declared as private
d) constructors
e) all of the above have return types
5) Which of the following method headers is most likely a header for a mutator method?
a) public int getAge()
b) public double computeSalary()
c) public Person()
d) public void setAge(int newAge)
e) none of these are headers for a mutator method
6) A _______________ variable is shared among all instances of a class.
a) static
b) final
c) public
d) private
e) none of the above
7) A(n) __________________ is an application that displays the inner workings of an executing program.
a) stethoscope
b) telescope
c) debugger
d) signal analyzer
e) oscilloscope
8) The ________________ reference always refers to the currently executing object.
a) null
b) static
c) final
d) actual
e) this
9) A method that has multiple definitions is an __________________ method.
a) overloaded
b) overridden
c) overlooked
d) overclocked
e) none of the above
10) A(n) ________________ is a step-by-step process for solving a problem.
a) UML diagram
b) aggregate object
c) class
d) algorithm
e) none of the above
11) All methods (with the exception of constructors) must specify a return type. What is the return type for a method that does not return any values?
a) int
b) public
c) double
d) void
e) none of the above
12) Methods that can be called directly through the class name and do not need to have an object instantiated are called _________________.
a) final
b) public
c) static
d) private
e) none of the above
13) A(n) ___________________ object is one that is made up, at least in part, of other objects.
a) static
b) aggregate
c) encapsulated
d) private
e) public
14) If a service is so complex that it cannot be reasonably be implemented using one method, it is often helpful to decompose it to make use of ________________ support methods.
a) static
b) aggregate
c) private
d) public
e) final
15) The versions of an overloaded method are distinguished by ___________________________.
a) the number, type and order of their parameters
b) their identifiers
c) their classes
d) the number and type of their parameters
e) the number of their parameters
1) A variable can always be referenced anywhere in a program.
2) An object can be thought of as a blueprint for a set of classes.
3) A return statement is not required at the end of every method.
4) Black-box testing uses the internal structure and implementation of the code to be tested in designing the tests.
5) A break point is a statement in a program that causes the program to crash.
6) A main method can only access static or local variables.
7) In a class that has variables called height and width, methods called getHeight() and getWidth() are examples of accessor methods.
8) Every class has a constructor, whether defined by the programmer or not.
9) Variables that are declared as static are shared among all instances of a class.
10) Aggregation is sometimes described as a has-a relationship.
1) What is the difference between an object and a class?
2) Explain the difference between actual parameters and formal parameters.
3) What is encapsulation? How can it be enforced in Java?
4) What is instance data?
5) Write a method called randomInRange that takes in two numbers representing a range. Print an error message and return zero if the second parameter is less than the first. Otherwise, the method should return a randomly generated integer in that range (inclusive). You may assume that the class has a static Random object called generator already declared and instantiated.
6) Write a method called isPalindrome that accepts a String as a parameter and returns true if the String is a palindrome, and false otherwise. You may assume that the entered String consists entirely of lowercase letters (meaning it contains no numbers, spaces, punctuation, etc). Hint: write code that creates a new string that is the original string reversed, and then check to see if the two strings are equal.
7) What is the difference between a service method and a support method in a class definition?
8) Can a static method access instance data in a class?
9) Student is a class that has the following instance variables: name (a String), yearInSchool (an int), and gpa (a double). Write a constructor for the Student class that takes parameters for these instance variables as initial values of the variables. Use the this reference in the constructor.
10) Java uses pass by value for passing parameters on a method call. What does this mean if the parameter is a primitive data type? What does this mean if the parameter is a reference to an object?
11) Give an example of how a static variable can be used in a class.
12) Method overloading requires that the methods have different signatures. What parts of a method are used in the signature?
13) Explain why method overloading is useful.
14) How are unit testing, integration testing, and system testing related? How are they different?
15) How can a print() or println() statement be used in debugging?
Document Information
Connected Book
Java Foundations 4th Edition | Test Bank with Answer Key by John Lewis
By John Lewis, Peter DePasquale, Joe Chase