Java Programming 8th Edition Joyce Farrell- Test Bank

 

To Purchase this Complete Test Bank with Answers Click the link Below

 

https://tbzuiqe.com/product/java-programming-8th-edition-joyce-farrell-test-bank/

 

If face any problem or Further information contact us At tbzuiqe@gmail.com

 

 

Sample Test

Chapter_03_Using_Methods_Classes_and_Objects

 

True / False

 

1. Any class can contain an unlimited number of methods.

 

a.

True

 

b.

False

 

ANSWER:  

True

POINTS:  

1

REFERENCES:  

120

 

2. The interface is the part of a method that the method’s client does not see.

 

a.

True

 

b.

False

 

ANSWER:  

False

POINTS:  

1

REFERENCES:  

129

 

3. Application classes frequently instantiate objects that use the objects of other classes.

 

a.

True

 

b.

False

 

ANSWER:  

True

POINTS:  

1

REFERENCES:  

144

 

4. You can identify a class that is an application because it contains a public static void main() method.

 

a.

True

 

b.

False

 

ANSWER:  

True

POINTS:  

1

REFERENCES:  

144

 

5. You can write your own constructor methods; but when you don’t write a constructor method for a class object, Java writes one for you.

 

a.

True

 

b.

False

 

ANSWER:  

True

POINTS:  

1

REFERENCES:  

155

 

6. A method body provides information about how other methods can interact with it.

 

a.

True

 

b.

False

 

ANSWER:  

False

POINTS:  

1

REFERENCES:  

123

 

7. An application’s main() method must have a void return type.

 

a.

True

 

b.

False

 

ANSWER:  

True

POINTS:  

1

REFERENCES:  

124

 

8. A method’s identifier must be more than one word, must have embedded spaces, and can be a Java keyword.

 

a.

True

 

b.

False

 

ANSWER:  

False

POINTS:  

1

REFERENCES:  

125

 

9. Parentheses in a method declaration contain parameters that are “dropped into” the method.

 

a.

True

 

b.

False

 

ANSWER:  

True

POINTS:  

1

REFERENCES:  

130

 

10. When a value is returned from a method, you are required to use the value when the method is called.

 

a.

True

 

b.

False

 

ANSWER:  

False

POINTS:  

1

REFERENCES:  

137

 

Multiple Choice

 

11. A(n) ____ is a program module that contains a series of statements that carry out a task.

 

a.

argument

b.

method

 

c.

application

d.

declaration

 

ANSWER:  

b

POINTS:  

1

REFERENCES:  

120

 

12. A method header is also called a(n) _____.

 

a.

argument

b.

address

 

c.

statement

d.

declaration

 

ANSWER:  

d

POINTS:  

1

REFERENCES:  

123

 

13. The ____ method executes first in an application, regardless of where you physically place it within its class.

 

a.

start()

b.

run()

 

c.

main()

d.

execute()

 

ANSWER:  

c

POINTS:  

1

REFERENCES:  

121

 

14. Data items you use in a call to a method are called ____.

 

a.

arguments

b.

instance variables

 

c.

method declarations

d.

headers

 

ANSWER:  

a

POINTS:  

1

REFERENCES:  

129

 

15. ____ is a principle of object-oriented programming that describes the encapsulation of method details within a class.

 

a.

An interface

b.

A calling method

 

c.

Implementation hiding

d.

Instantiation

 

ANSWER:  

c

POINTS:  

1

REFERENCES:  

129

 

16. A(n) ____ variable is known only within the boundaries of the method.

 

a.

method

b.

local

 

c.

double

d.

instance

 

ANSWER:  

b

POINTS:  

1

REFERENCES:  

131

 

17. When a variable ceases to exist at the end of a method, programmers say the variable ____.

 

a.

is undeclared

b.

is out of memory range

 

c.

goes out of scope

d.

is lost

 

ANSWER:  

c

POINTS:  

1

REFERENCES:  

133

 

18. The arguments in a method call are often referred to as ____.

 

a.

constants

b.

concept parameters

 

c.

actual parameters

d.

argument lists

 

ANSWER:  

c

POINTS:  

1

REFERENCES:  

135

 

19. A(n) ____ causes a value to be sent from a called method back to the calling method.

 

a.

return statement

b.

method statement

 

c.

instantiation

d.

inheritance relationship

 

ANSWER:  

a

POINTS:  

1

REFERENCES:  

136

 

20. Every object is a _____ of a more general class.

 

a.

constant

b.

member

 

c.

method

d.

field

 

ANSWER:  

b

POINTS:  

1

REFERENCES:  

142

 

21. Method names that begin with ____ and set are very typical.

 

a.

next

b.

call

 

c.

read

d.

get

 

ANSWER:  

d

POINTS:  

1

REFERENCES:  

143

 

22. Public classes are accessible by all objects, which means that public classes can be ____, or used as a basis for any other class.

 

a.

saved

b.

extended

 

c.

copied

d.

used

 

ANSWER:  

b

POINTS:  

1

REFERENCES:  

145

 

23. Assigning ____ to a field means that no other classes can access the field’s values.

 

a.

user rights

b.

protected access

 

c.

key access

d.

private access

 

ANSWER:  

d

POINTS:  

1

REFERENCES:  

146

 

24. Methods used with object instantiations are called ____ methods.

 

a.

accessor

b.

internal

 

c.

static

d.

instance

 

ANSWER:  

d

POINTS:  

1

REFERENCES:  

147

 

25. Methods that retrieve values are called ____ methods.

 

a.

static

b.

accessor

 

c.

class

d.

mutator

 

ANSWER:  

b

POINTS:  

1

REFERENCES:  

147

 

26. A(n) ____ method is a method that creates and initializes class objects.

 

a.

constructor

b.

accessor

 

c.

non-static

d.

instance

 

ANSWER:  

a

POINTS:  

1

REFERENCES:  

155

 

27. A unique identifier is most likely used as a ____ key in a database.

 

a.

special

b.

public

 

c.

static

d.

primary

 

ANSWER:  

d

POINTS:  

1

REFERENCES:  

150

 

28. For ease in locating class methods, many programmers store them in ____ order.

 

a.

chronological

b.

type

 

c.

alphabetical

d.

numeric

 

ANSWER:  

c

POINTS:  

1

REFERENCES:  

151

 

29. A(n) ____ constructor is one that requires no arguments.

 

a.

class

b.

default

 

c.

explicit

d.

write

 

ANSWER:  

b

POINTS:  

1

REFERENCES:  

159

 

30. The name of the ____ is always the same as the name of the class whose objects it constructs.

 

a.

method

b.

constructor

 

c.

argument

d.

variable

 

ANSWER:  

b

POINTS:  

1

REFERENCES:  

155

 

31. After an object has been instantiated, its methods can be accessed using the object’s _____, a dot, and a method call.

 

a.

identifier

b.

class

 

c.

operator

d.

output

 

ANSWER:  

a

POINTS:  

1

REFERENCES:  

155

 

32. When an application is run, the method that must be executed first must be named ____.

 

a.

first()

b.

void()

 

c.

main()

d.

final()

 

ANSWER:  

c

POINTS:  

1

REFERENCES:  

125

 

33. ____ parameters are variables in a method declaration that accept the values from the actual parameters.

 

a.

System

b.

Formal

 

c.

Public

d.

Static

 

ANSWER:  

b

POINTS:  

1

REFERENCES:  

135

 

34. In order to allocate the needed memory for an object, you must use the ____ operator.

 

a.

new

b.

main

 

c.

type

d.

return

 

ANSWER:  

a

POINTS:  

1

REFERENCES:  

154

 

35. Which of the following is NOT an initial value assigned to an object’s data field by a default constructor?

 

a.

numeric fields set to 0

b.

Boolean fields set to true

 

c.

character fields set to Unicode ‘\u0000’

d.

a field of object references set to null

 

ANSWER:  

b

POINTS:  

1

REFERENCES:  

159-160

 

Completion

 

36. To execute a method, you ____________________ it from another method.

ANSWER:  

invoke
call

POINTS:  

1

REFERENCES:  

120

 

37. Access specifiers are sometimes called access ____________________.

ANSWER:  

modifiers

POINTS:  

1

REFERENCES:  

124

 

38. Often, programmers list the ____________________ first because it is the first method used when an object is created.

ANSWER:  

constructor

POINTS:  

1

REFERENCES:  

160

 

39. A(n) ____________________ data type is a type whose implementation is hidden and accessed through its public methods.

ANSWER:  

abstract

POINTS:  

1

REFERENCES:  

163

 

40. Normally, you declare constructors to be ____________________ so that other classes can instantiate objects that belong to the class.

ANSWER:  

public

POINTS:  

1

REFERENCES:  

160

 

Matching

 

Match each term with the correct statement below.

a.

return statement

b.

header

c.

instance variables

d.

method’s signature

e.

formal parameters

f.

static method

g.

data fields

h.

parameter type

i.

class user

 

REFERENCES:  

136
123
169
134
135
148
130
144

 

41. The first line of a method

ANSWER:  

b

POINTS:  

1

 

42. The combination of the method name and the number, types, and order of arguments

ANSWER:  

d

POINTS:  

1

 

43. Included within the method declaration parentheses

ANSWER:  

h

POINTS:  

1

 

44. Are called class methods

ANSWER:  

f

POINTS:  

1

 

45. Variables in the method declaration that accept the values from the actual parameters

ANSWER:  

e

POINTS:  

1

 

46. Used to return a value back to the calling method

ANSWER:  

a

POINTS:  

1

 

47. Data components of a class

ANSWER:  

c

POINTS:  

1

 

48. An application or a class that instantiates objects of another prewritten class

ANSWER:  

i

POINTS:  

1

 

49. Variables you declare within a class, but outside of any method

ANSWER:  

g

POINTS:  

1

 

Subjective Short Answer

 

50. What is a method and how is one used?

ANSWER:  

A method is a program module that contains a series of statements that carry out a task. To execute a method, you invoke or call it from another method; the calling method makes a method call, which invokes the called method. Any class can contain an unlimited number of methods, and each method can be called an unlimited number of times.

POINTS:  

1

REFERENCES:  

120

 

51. What are the four components of a method header?

ANSWER:  

Optional access specifiers

A return type

An identifier

Parentheses

POINTS:  

1

REFERENCES:  

123

 

52. How does the order in which methods appear in a class affect how the application executes? Please explain.

ANSWER:  

The order in which methods appear in a class has no bearing on the order in which the methods are called or execute. No matter where you place it, the main() method is always executed first in any Java application, and it might call any other methods in any order and any number of times. The order in which you call methods, not their physical placement, is what makes a difference in how an application executes.

POINTS:  

1

REFERENCES:  

121

 

53. What are the two parts of every method? Describe them.

ANSWER:  

A method header—A method’s header provides information about how other methods can interact with it. A method header is also called a declaration.

A method body between a pair of curly braces—The method body contains the statements that carry out the work of the method. A method’s body is called its implementation. Technically, a method is not required to contain any statements in its body, but you usually would have no reason to create an empty method in a class. Sometimes, while developing a program, the programmer creates an empty method as a placeholder and fills in the implementation later. An empty method is called a stub.

POINTS:  

1

REFERENCES:  

123

 

54. Describe how you can use multiple arguments in a method. Provide an example.

ANSWER:  

You can pass multiple arguments to a method by listing the arguments within the call to the method and separating them with commas. When values are passed to the method in a statement such as the following, the first value passed is referenced as salary within the method, and the second value passed is referenced as rate:
predictRaiseUsingRate(mySalary, promisedRate);

Arguments to a method must be passed in the correct order.

POINTS:  

1

REFERENCES:  

133

 

55. How do you use a value returned from a method? Provide an example.

ANSWER:  

If a method returns a value, then when you call the method, you normally use the returned value, although you are not required to do so. For example, when you invoke the predictRaise() method, you might want to assign the returned value (also called the method’s value) to a double variable named myNewSalary, as in the following statement:

myNewSalary = predictRaise(mySalary);

The predictRaise() method returns a double, so it is appropriate to assign the method’s returned value to a double variable.

POINTS:  

1

REFERENCES:  

137

 

56. Describe instantiation and how it relates to ‘is-a relationships.’

ANSWER:  

Everything is an object, and every object is a member of a more general class. Your desk is a member of the class that includes all desks, and your pet fish is a member of the class that contains all fish. These statements represent is-a relationships—that is, relationships in which the object “is a” concrete example of the class. The difference between a class and an object parallels the difference between abstract and concrete. An object is an instantiation of a class, or one tangible example of a class.

POINTS:  

1

REFERENCES:  

142-143

 

57. Does a programmer need to write every class he or she uses? Why or why not?

ANSWER:  

The same programmer does not need to write every class he or she uses. Often, you will write programs that use classes created by others. For example, many programs you have seen so far in this book have used the System class. You did not have to create it or its println() method; both were provided for you by Java’s creators. Similarly, you might create a class that others will use to instantiate objects within their own applications.

POINTS:  

1

REFERENCES:  

144

 

58. Describe what a public access class is and when you would use one.

ANSWER:  

The most liberal form of access is public. The keyword public is a class modifier. Classes that are public are accessible by all objects. Public classes also can be extended, or used as a basis for any other class. Making access public means that if you develop a good Employee class, and someday you want to develop two classes that are more specific, SalariedEmployee and HourlyEmployee, then you do not have to start from scratch.

POINTS:  

1

REFERENCES:  

145

 

59. How do you create an object that is an instance of a class? Provide an example.

ANSWER:  

A two-step process creates an object that is an instance of a class. First, you supply a type and an identifier—just as when you declare any variable—and then you allocate computer memory for that object. For example, you might define an integer as int someValue; and you might define an Employee as follows: Employee someEmployee;. In this statement, someEmployee can be any legal identifier, but objects conventionally start with a lowercase letter.

POINTS:  

1

REFERENCES:  

154

 

60. What is the difference between a mutator method and an accessor method? Provide an example of each.

ANSWER:  

Methods that set or change field values are called mutator methods; methods that retrieve values are called accessor methods. In Java, mutator methods conventionally start with the prefix set, and accessor methods conventionally start with the prefix get.

Mutator example:

public void setEmpNum(int emp)

{
empNum = emp;
}

Accessor example:

public int getEmpNum()
{
return empNum;
}

POINTS:  

1

REFERENCES:  

147

 

61. Describe fully qualified identifiers and explain why they are necessary.

ANSWER:  

A complete name that includes the class is a fully qualified identifier. If you want to use a method in another class, the compiler does not recognize the method unless you use the full name. A fully qualified identifier includes the class time, a dot, and the method name.

POINTS:  

1

REFERENCES:  

125-126

 

62. Explain the purpose of a return type of a method. Describe the return value of a method that returns no data.

ANSWER:  

A return type describes the type of data the method sends back to its calling method. Not all methods return a value to their calling methods; a method that returns no data has a return type of void.

POINTS:  

1

REFERENCES:  

124

 

63. What are the possible results if arguments to a method are passed in the wrong order?

ANSWER:  

If arguments to a method are passed in the wrong order, the result is one of the following:

If the method can still accept both arguments, the result is a logical error; that is, the program compiles and executes, but it probably produces incorrect results.

If the method cannot accept the arguments, passing arguments in the wrong order constitutes a syntax error, and the program does not compile.

POINTS:  

1

REFERENCES:  

134

 

64. When creating a method that requires multiple parameters, why would a programmer need to understand a method’s signature, and why must a method call match the called method’s signature?

ANSWER:  

You can write a method so that it takes any number of parameters in any order. However, when you call a method, the arguments you send to a method must match in order—both in number and in type—the parameters listed in the method declaration. A method’s signature is the combination of the method name and the number, types, and order of arguments. A method call must match the called method’s signature.

POINTS:  

1

REFERENCES:  

134

 

65. public static void predictRaise(double salary)
{
double newSalary;
final double RAISE_RATE = 1.10;
newSalary = salary * RAISE_RATE;
System.out.println(“Current salary: ” +
salary + ” After raise: ” +
newSalary);
}

In the above code, what are the parameter data type and parameter identifier? How do you identify each?

ANSWER:  

When you write the method declaration for a method that can receive a parameter, you define the optional access specifiers, the return type for the method, the method name, the parameter type, and a local name for the parameter. In the method header for predictRaise(), the parameter double salary within the parentheses indicates that the method will receive a value of type double, and that within the method, the passed value will be known as salary.

POINTS:  

1

REFERENCES:  

132

 

66.

In the above code, what would happen if the arguments passed to the method were passed in the wrong order?

ANSWER:  

Since the two methods are of the same type, there would be no syntax or compile error, but there would be a logic error and the program would produce incorrect results. The newAmount value calculated would produce a result based on rate * (1 + salary) instead of salary * (1 + rate).

POINTS:  

1

REFERENCES:  

133

 

67.

Fill in the blank line in the above code to add a statement that calls a method named practiceWithCalls that passes a parameter named testing of type double.

ANSWER:  

The line of code to call the method would appear as follows:

practiceWithCalls(double testing);

POINTS:  

1

REFERENCES:  

130

 

68. A major advantage of a method is that it is easily reusable. What does it mean to reuse a method and what are the advantages of doing so?

ANSWER:  

After a method is created, you can use it in any application. You write the method once and then use the method unlimited times. This saves time in writing code and makes the code easier to manage.

POINTS:  

1

REFERENCES:  

120-121

 

69.
Identify and describe the four components that make up the method header above.

ANSWER:  

1. Optional access specifier – can be public (most common), private, protected, or package
2. Return type – describes the type of data the method will send back to the calling method
3. An identifier – consists of one word with no embedded spaces and cannot be a Java keyword
4. Parentheses – may contain data to be sent to the method, but may be empty if no outside data is required

POINTS:  

1

REFERENCES:  

123-125

 

70.

In the above code, the calculateBonus() method acts as a “black box.” What does this mean?

ANSWER:  

The predictRaise method calls the calculateBonus() method. However, you do not know how the calculateBonus() method actually works. You only know that it accepts a double as a parameter (because newAmount is passed into it) and that it must return either a double or a type that can automatically be promoted to a double. In this way, the method acts as a black box.

POINTS:  

1

REFERENCES:  

129,138,142

 

71. Write a valid class header with public access. Assign a valid identifier of your choice. Then write the body of the class that contains one data field named myPractice with a data type of double. Be sure to include any necessary curly braces and semicolons.

ANSWER:  

public class PublicClass     (identifier name may vary)

{

private double myPractice;

}

POINTS:  

1

REFERENCES:  

145-146

 

72. public int getStudentNum()

{

return studentNum;

}

In the above code, identify if the method is a mutator method or an accessor method. Describe how the two types of methods differ and how they are similar.

ANSWER:  

Methods that set or change field values are called mutator methods; methods that retrieve

values are called accessor methods. In Java, mutator methods conventionally start with the

prefix set, and accessor methods conventionally start with the prefix get. Using these three-letter prefixes with your method names is not required, but it is conventional.

​The method in the above code is an accessor method because it retrieves studentNum.

POINTS:  

1

REFERENCES:  

147

 

73. public Employee()
{
empSalary = 300.00;
}

​The above code shows the Employee class constructor. What is a constructor and how would this default constructor operate?

ANSWER:  

A constructor establishes an object. A default constructor is one that requires no arguments. A default constructor is created automatically by the Java compiler for any class you create whenever you do not write your own constructor. When the prewritten, default constructor for the Employee class is called, it establishes one Employee object with the identifier provided. The automatically supplied default constructor provides the following specific initial values to an object’s data fields:

Numeric fields are set to 0 (zero).

Character fields are set to Unicode ‘\u0000’.

Boolean fields are set to false.

Fields that are object references (for example, String fields) are set to null (or empty).

In this example, a field named empSalary in the Employee object is assigned a value of 300.00.

POINTS:  

1

REFERENCES:  

159-160

 

74. public class Employee
{
private int empNum;
private double empSalary;

public void setEmpNum(int emp)
{
empNum = emp;
}

public void setEmpSalary(double sal)

{

empSalary = sal;

}

}

Given the class defined in the code above, write the Java statements that will create a new employee instance called employee15 and assign an empNum of 15 and empSalary of 500.00 to that employee instance.

ANSWER:  

Employee employee15;

employee15 = new Employee();

employee15.setEmpNum(15);

employee15.setEmpSalary(500.00);

POINTS:  

1

REFERENCES:  

154-155

 

Chapter_05_Making_Decisions

 

 

True / False

 

1. You write pseudocode in everyday language, not the syntax used in a programming language.

 

a.

True

 

b.

False

 

ANSWER:  

True

POINTS:  

1

REFERENCES:  

246

 

2. An alternative to using a Boolean expression, such as someVariable == 10, is to store the Boolean expression’s value in a Boolean variable.

 

a.

True

 

b.

False

 

ANSWER:  

True

POINTS:  

1

REFERENCES:  

249

 

3. When you create a block, you must place multiple statements within it.

 

a.

True

 

b.

False

 

ANSWER:  

False

POINTS:  

1

REFERENCES:  

255

 

4. When you use nested if statements, you must pay careful attention to placement of any else clauses.

 

a.

True

 

b.

False

 

ANSWER:  

True

POINTS:  

1

REFERENCES:  

261

 

5. In the switch structure, break is followed by one of the possible values for the test expression and a colon.

 

a.

True

 

b.

False

 

ANSWER:  

False

POINTS:  

1

REFERENCES:  

276

 

6. Computers contain switches that are set to on or off.

 

a.

True

 

b.

False

 

ANSWER:  

True

POINTS:  

1

REFERENCES:  

247

 

7. When writing a statement with the two-line format, you must be sure to type a semicolon at the end of the first line in order to ensure accurate results.

 

a.

True

 

b.

False

 

ANSWER:  

False

POINTS:  

1

REFERENCES:  

249

 

8. Although it is possible to block statements that depend on an if, you cannot likewise block statements that depend on an else.

 

a.

True

 

b.

False

 

ANSWER:  

False

POINTS:  

1

REFERENCES:  

257

 

9. Although not required, it is common procedure to align the keyword if with the keyword else.

 

a.

True

 

b.

False

 

ANSWER:  

True

POINTS:  

1

REFERENCES:  

251-252

 

10. You use the NOT operator, which is written as the exclamation point (!), to negate the result of any Boolean expression.

 

a.

True

 

b.

False

 

ANSWER:  

True

POINTS:  

1

REFERENCES:  

281

 

Multiple Choice

 

11. A ____ consists of written steps in diagram form, as a series of shapes connected by arrows.

 

a.

pseudocode chart

b.

flowchart

 

c.

sequence structure

d.

decision structure

 

ANSWER:  

b

POINTS:  

1

REFERENCES:  

246

 

12. A logical structure called a(n) ____ structure is when one step follows another unconditionally.

 

a.

straight

b.

decision

 

c.

sequence

d.

unconditional

 

ANSWER:  

c

POINTS:  

1

REFERENCES:  

246

 

13. The simplest statement you can use to make a decision is the ____ statement.

 

a.

this

b.

Boolean

 

c.

true false

d.

if

 

ANSWER:  

d

POINTS:  

1

REFERENCES:  

248

 

14. When an expression containing a ____ is part of an if statement, the assignment is illegal.

 

a.

single equal sign

b.

greater than sign

 

c.

double equal sign

d.

Boolean value

 

ANSWER:  

a

POINTS:  

1

REFERENCES:  

 

Comments

Popular posts from this blog

Illustrated Course Guides Teamwork & Team Building – Soft Skills for a Digital Workplace, 2nd Edition by Jeff Butterfield – Test Bank

International Financial Management, Abridged 12th Edition by Madura – Test Bank

Information Security And IT Risk Management 1st Edition by Manish Agrawal – Test Bank