Ch6 A First Look at Classes Complete Test Bank - Java Control Structures 7e Test Bank by Tony Gaddis. DOCX document preview.

Ch6 A First Look at Classes Complete Test Bank

Starting Out with Java: From Control Structures through Objects 7e (Gaddis)

Chapter 6 A First Look at Classes

TRUE/FALSE

1. An access specifier indicates how a class may be accessed.

2. A method that gets a value from a class's field but does not change it is known as a mutator method.

3. The term "no-arg constructor" is applied to any constructor that does not accept arguments.

4. When a local variable in an instance method has the same name as an instance field, the instance field hides the local variable.

5. The public access specifier for a field indicates that the field may not be accessed by statements outside the class.

6. The term "default constructor" is applied to the first constructor written by the author of the class.

7. A method that stores a value in a class's field or in some other way changes the value of a field is known as a mutator method.

8. A constructor is a method that is automatically called when an object is created.

9. The java.lang package is automatically imported into all Java programs.

10. Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter variable.

11. An object can store data.

12. A class is not an object. It is a description of an object.

13. Instance methods should be declared static.

14. Instance methods do not have the key word static in their headers.

15. When an object is passed as an argument to a method, the object's address is passed into the method's parameter variable.

MULTIPLE CHOICE

1. When an object is created, the attributes associated with the object are called __________.

a.

instance fields

c.

instance methods

b.

class instances

d.

fixed attributes

2. A class's responsibilities include __________.

a.

the things a class is responsible for knowing

b.

the things a class is responsible for doing

c.

both of these

d.

neither of these

3. Data hiding (which means that critical data stored inside the object is protected from code outside the object) is accomplished in Java by __________.

a.

using the public access specifier on the class methods

b.

using the private access specifier on the class methods

c.

using the private access specifier on the class fields

d.

using the private access specifier on the class definition

4. Methods that operate on an object's fields are called __________.

a.

instance methods

c.

private methods

b.

instance variables

d.

public methods

5. A group of related classes is called a(n) __________.

a.

archive

c.

collection

b.

package

d.

attachment

6. Class objects normally have __________ that perform useful operations on their data, but primitive variables do not.

a.

fields

c.

methods

b.

relationships

d.

instances

7. You should not define a class that is dependent on the values of other class fields __________.

a.

in order to keep it current

b.

because it is redundant

c.

in order to avoid having stale data

d.

because it should be defined in another class

8. Another term for an object of a class is a(n) __________.

a.

access specifier

c.

member

b.

instance

d.

method

9. Which symbol indicates that a member is public in a UML diagram?

a.

-

b.

*

c.

#

d.

+

10. Which symbol indicates that a member is private a UML diagram?

a.

-

b.

*

c.

#

d.

+

11. What does the following UML diagram entry mean?

+ setHeight(h : double) : void

a.

a public method with a parameter of data type double that does not return a value

b.

a private field called setHeight that is a double data type

c.

a private method with no parameters that returns a double data type

d.

a public field called setHeight that is a double data type

12. Which of the following is not involved in identifying the classes to be used when developing an object-oriented application?

a.

a description of the problem domain

b.

the code

c.

a refined list of nouns that include only those relevant to the problem

d.

all the nouns are identified

13. A constructor is a method that __________.

a.

returns an object of the class

b.

never receives any arguments

c.

performs initialization or setup operations

d.

removes the object from memory

14. It is common practice in object-oriented programming to make all of a class's __________.

a.

fields private

c.

fields public

b.

methods private

d.

fields and methods public

15. A class specifies the __________ and __________ that a particular type of object has.

a.

relationships, methods

c.

fields, methods

b.

fields, object names

d.

relationships, object names

16. __________ refers to combining data and code into a single object.

a.

Data hiding

c.

The constructor

b.

Abstraction

d.

Encapsulation

17. For the following code, which statement is not true?

public class Sphere

{

private double radius;

public double x;

private double y;

private double z;

}

a.

The z field is available to code written outside the Sphere class.

b.

The radius field is not available to code written outside the Sphere class.

c.

The radius, x, y, and z fields are members of the Sphere class.

d.

The x field is available to code that is written outside the Sphere class.

18. For the following code, which statement is not true?

public class Circle

{

private double radius;

public double x;

private double y;

}

a.

The y field is available to code written outside the Circle class.

b.

The radius field is not available to code written outside the Circle class.

c.

The radius, x, and y fields are members of the Circle class.

d.

The x field is available to code that is written outside the Circle class.

19. The following statement is an example of __________.

import java.util.Scanner;

a.

an explicit import statement

b.

an unconditional import statement

c.

a wildcard import statement

d.

a conditional import statement

20. The following statement is an example of __________.

import java.util.*;

a.

an explicit import statement

b.

an unconditional import statement

c.

a wildcard import statement

d.

a conditional import statement

21. After the header, the body of the method appears inside a set of __________.

a.

braces, { }

c.

brackets, [ ]

b.

parentheses, ( )

d.

double quotes, " "

22. One or more objects may be created from a(n) __________.

a.

field

b.

method

c.

instance

d.

class

23. A constructor __________.

a.

always accepts two arguments

c.

has the return type of void

b.

has the same name as the class

d.

always has a private access specifier

24. The scope of a private instance field is __________.

a.

the instance methods of the same class

b.

inside the class but not inside any method in that class

c.

inside the parentheses of a method header

d.

the method in which it is defined

25. To indicate the data type of a variable in a UML diagram, you enter __________.

a.

the variable name followed by the data type

b.

the variable name followed by a colon and the data type

c.

the class name followed by the variable name followed by the data type

d.

the data type followed by the variable name

26. Two or more methods in a class may have the same name as long as __________.

a.

they have different return types

b.

they have different parameter lists

c.

they have different return types but the same parameter list

d.

You cannot have two methods with the same name.

27. The scope of a public instance field is __________.

a.

only the class in which it is defined

b.

inside the class but not inside any method

c.

inside the parentheses of a method header

d.

the instance methods and methods outside the class

28. Overloading means that multiple methods in the same class __________.

a.

have the same name but different return types

b.

have different names but the same parameter list

c.

have the same name but different parameter lists

d.

perform the same function

29. When an object is passed as an argument to a method, what is passed into the method's parameter variable?

a.

the class name

c.

the values for each field

b.

the object's memory address

d.

the method names

30. A constructor __________.

a.

always accepts two arguments

b.

has the return type of void

c.

has the same name as the class

d.

always has a private access specifier

31. A(n) __________ can be thought of as a blueprint that can be used to create a type of __________.

a.

object, class

c.

cookie, cake

b.

class, object

d.

object, method

32. When you work with a __________, you are using a storage location that holds a piece of data.

a.

primitive variable

c.

numeric literal

b.

reference variable

d.

binary number

33. A reference variable stores a(n) __________.

a.

binary encoded decimal

c.

object

b.

memory address

d.

string

34. Most of the programming languages used today are __________.

a.

procedural

c.

object-oriented

b.

top-down

d.

functional

35. A UML diagram does not contain __________.

a.

the class name

c.

the field names

b.

the method names

d.

the object names

36. Methods that operate on an object's fields are called __________.

a.

instance variables

c.

public methods

b.

instance methods

d.

private methods

37. Java allows you to create objects of the __________ class in the same way you would create primitive variables.

a.

Random

c.

PrintWriter

b.

String

d.

Scanner

38. Which of the following statements will create a reference, str, to the String "Hello, World"?

a.

String str = "Hello, World";

b.

string str = "Hello, World";

c.

String str = new "Hello, World";

d.

str = "Hello, World";

39. Instance methods do not have the __________ key word in their headers.

a.

public

b.

static

c.

private

d.

protected

40. The __________ package is automatically imported into all Java programs.

a.

java.java

c.

java.util

b.

java.default

d.

java.lang

41. Given the following code, what will be the value of finalAmount when it is displayed?

public class Order

{

private int orderNum;

private double orderAmount;

private double orderDiscount;

public Order(int orderNumber, double orderAmt,

double orderDisc)

{

orderNum = orderNumber;

orderAmount = orderAmt;

orderDiscount = orderDisc;

}

public int getOrderAmount()

{

return orderAmount;

}

public int getOrderDisc()

{

return orderDisc;

}

}

public class CustomerOrder

{

public static void main(String[] args)

{

int ordNum = 1234;

double ordAmount = 580.00;

double discountPer = .1;

Order order;

double finalAmount = order.getOrderAmount() —

order.getOrderAmount() * order.getOrderDisc();

System.out.printf("Final order amount = $%,.2f\n",

finalAmount);

}

}

a.

528.00

b.

580.00

c.

There is no value because the constructor has an error.

d.

There is no value because the object, order, has not been created.

42. Given the following code, what will be the value of finalAmount when it is displayed?

public class Order

{

private int orderNum;

private double orderAmount;

private double orderDiscount;

public Order(int orderNumber, double orderAmt,

double orderDisc)

{

orderNum = orderNumber;

orderAmount = orderAmt;

orderDiscount = orderDisc;

}

public double finalOrderTotal()

{

return orderAmount - orderAmount * orderDiscount;

}

}

public class CustomerOrder

{

public static void main(String[] args)

{

Order order;

int orderNumber = 1234;

double orderAmt = 580.00;

double orderDisc = .1;

order = new Order(orderNumber, orderAmt, orderDisc);

double finalAmount = order.finalOrderTotal();

System.out.printf("Final order amount = $%,.2f\n",

finalAmount);

}

}

a.

528.00

b.

580.00

c.

522.00

d.

There is no value because the object, order, has not been created.

MULTIPLE RESPONSE

1. Select all that apply. Which of the following are classes from the Java API?

a.

Scanner

c.

Package

b.

Random

d.

PrintWriter

Document Information

Document Type:
DOCX
Chapter Number:
6
Created Date:
Aug 21, 2025
Chapter Name:
Chapter 6 A First Look at Classes
Author:
Tony Gaddis

Connected Book

Java Control Structures 7e Test Bank

By Tony Gaddis

Test Bank General
View Product →

$24.99

100% satisfaction guarantee

Buy Full Test Bank

Benefits

Immediately available after payment
Answers are available after payment
ZIP file includes all related files
Files are in Word format (DOCX)
Check the description to see the contents of each ZIP file
We do not share your information with any third party