Java Chapter 6

Your page rank:

Total word count: 1992
Pages: 7

Calculate the Price

- -
275 words
Looking for Expert Opinion?
Let us have a look at your work and suggest how to improve it!
Get a Consultant

1) One or more objects may be created from a(n):
A) field
B) class
C) method
D) instance

Answer: B

2) Class objects normally have ________ that perform useful operations on their data, but primitive
variables do not.
A) fields
B) instances
C) methods
D) relationships

Answer: C

3) In the cookie cutter metaphor, think of the ________ as a cookie cutter and ________ as the cookies.
A) object; classes
B) class; objects
C) class; fields
D) attribute; methods

Answer: B

4) Which of the following are classes from the Java API?
A) Scanner
B) Random
C) PrintWriter
D) All of the above

Answer: D

5) When you are working with a ________, you are using a storage location that holds a piece of data.
A) primitive variable
B) reference variable
C) numeric literal
D) binary number

Answer: A

6) What is stored by a reference variable?
A) A binary encoded decimal
B) A memory address
C) An object
D) A string

Answer: B

7) Most programming languages that are in use today are:
A) procedural
B) logic
C) object-oriented
D) functional

Answer: C

8) Java allows you to create objects of this class in the same way you would create primitive variables.
A) Random
B) String
C) PrintWriter
D) Scanner

Answer: B

9) A UML diagram does not contain:
A) the class name
B) the method names
C) the field names
D) object names

Answer: D

10) 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 definition
D) using the private access specifier on the class fields

Answer: D

11) 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) x is available to code that is written outside the Circle class.
B) radius is not available to code written outside the Circle class.
C) radius, x, y, and z are called members of the Circle class.
D) z is available to code that is written outside the Circle class.

Answer: D

12) You should not define a class field that is dependent upon the values of other class fields:
A) in order to avoid having stale data
B) because it is redundant
C) because it should be defined in another class
D) in order to keep it current

Answer: A

13) What does the following UML diagram entry mean?
+ setHeight(h : double) : void
A) this is a public attribute named Height and is a double data type
B) this is a private method with no parameters and returns a double data type
C) this is a private attribute named Height and is a double data type
D) this is a public method with a parameter of data type double and does not return a value

Answer: D

14) Methods that operate on an object’s fields are called:
A) instance variables
B) instance methods
C) public methods
D) private methods

Answer: B

15) 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
C) inside the parentheses of a method header
D) the method in which they are defined

Answer: A

16) A constructor:
A) always accepts two arguments
B) has return type of void
C) has the same name as the class
D) always has an access specifier of private

Answer: C

17) 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";

Answer: A

18) 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

Answer: B

19) 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.

Answer: D

20) A class specifies the ________ and ________ that a particular type of object has.
A) relationships; methods
B) fields; object names
C) fields; methods
D) relationships; object names

Answer: C

21) This refers to the combining of data and code into a single object.
A) Data hiding
B) Abstraction
C) Object
D) Encapsulation

Answer: D

22) Another term for an object of a class is:
A) access specifier
B) instance
C) member
D) method

Answer: B

23) In your textbook the general layout of a UML diagram is a box that is divided into three sections. The
top section has the ________; the middle section holds ________; the bottom section holds ________.
A) class name; attributes or fields; methods
B) class name; object name; methods
C) object name; attributes or fields; methods
D) object name; methods; attributes or fields

Answer: A

24) For the following code, which statement is NOT true?
public class Circle
{
private double radius;
public double x;
private double y;
}
A) x is available to code that is written outside the Circle class.
B) radius is not available to code written outside the Circle class.
C) radius, x, and y are called members of the Circle class.
D) y is available to code that is written outside the Circle class.

Answer: D

25) It is common practice in object-oriented programming to make all of a class’s:
A) methods private
B) fields private
C) fields public
D) fields and methods public

Answer: B

26) After the header, the body of the method appears inside a set of:
A) brackets, []
B) parentheses, ()
C) braces, {}
D) double quotes, ""

Answer: C

27) In UML diagrams, this symbol indicates that a member is private:
A) *
B) #
C) –
D) +

Answer: C

28) In UML diagrams, this symbol indicates that a member is public.
A) /
B) @
C) –
D) +

Answer: D

29) In a UML diagram to indicate the data type of a variable 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

Answer: B

30) When an object is created, the attributes associated with the object are called:
A) instance fields
B) instance methods
C) fixed attributes
D) class instances

Answer: A

31) When an object is passed as an argument to a method, what is passed into the method’s parameter
variable?
A) the class name
B) the object’s memory address
C) the values for each field
D) the method names

Answer: B

32) A constructor is a method that:
A) returns an object of the class.
B) never receives any arguments.
C) with the name ClassName.constructor.
D) performs initialization or setup operations.

Answer: D

33) 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

Answer: D

34) Which of the following statements will create a reference, str, to the string, "Hello, world"?
(1) String str = new String("Hello, world");
(2) String str = "Hello, world";
A) 1
B) 2
C) 1 and 2
D) neither 1 or 2

Answer: C

35) Overloading means 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

Answer: C

36) 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.

Answer: C

37) A class’s responsibilities include:
A) the things a class is responsible for doing
B) the things a class is responsible for knowing
C) both A and B
D) neither A nor B

Answer: C

38) Instance methods do not have this key word in their headers:
A) public
B) static
C) private
D) protected

Answer: B

39) Which of the following is NOT involved in finding the classes when developing an object-oriented
application?
A) Describe the problem domain.
B) Identify all the nouns.
C) Write the code.
D) Refine the list of nouns to include only those that are relevant to the problem.

Answer: C

40) This is a group of related classes.
A) archive
B) package
C) collection
D) attachment

Answer: B

41) Quite often you have to use this statement to make a group of classes available to a program.
A) import
B) use
C) link
D) assume

Answer: A

42) Look at the following statement.
import java.util.Scanner;
This is an example of
A) a wildcard import
B) an explicit import
C) unconditional import
D) conditional import

Answer: B

43) Look at the following statement.
import java.util.*;
This is an example of:
A) a wildcard import
B) an explicit import
C) unconditional import
D) conditional import

Answer: A

44) The following package is automatically imported into all Java programs.
A) java.java
B) java.default
C) java.util
D) java.lang

Answer: D

T/F: 1) An object can store data.

Answer: TRUE

T/F: 2) A class in not an object, but a description of an object.

Answer: TRUE

T/F: 3) An access specifier indicates how the class may be accessed.

Answer: TRUE

T/F: 4) 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.

Answer: TRUE

T/F: 5) Instance methods should be declared static.

Answer: FALSE

T/F: 6) A constructor is a method that is automatically called when an object is created.

Answer: TRUE

T/F: 7) Shadowing is the term used to describe where the field name is hidden by the name of a local or
parameter variable.

Answer: TRUE

T/F: 8) The public access specifier for a field indicates that the attribute may not be accessed by statements
outside the class.

Answer: FALSE

T/F: 9) A method that gets a value from a class’s field but does not change it is known as a mutator method.

Answer: FALSE

T/F: 10) Instance methods do not have the key word static in their headers

Answer: TRUE

T/F: 11) The term "default constructor" is applied to the first constructor written by the author of a class.

Answer: FALSE

T/F: 12) When a local variable in an instance method has the same name as an instance field, the instance field
hides the local variable.

Answer: FALSE

T/F: 13) The term "no-arg constructor" is applied to any constructor that does not accept arguments.

Answer: TRUE

T/F: 14) The java.lang package is automatically imported into all Java programs.

Answer: TRUE

Share This
Flashcard

More flashcards like this

NCLEX 10000 Integumentary Disorders

When assessing a client with partial-thickness burns over 60% of the body, which finding should the nurse report immediately? a) ...

Read more

NCLEX 300-NEURO

A client with amyotrophic lateral sclerosis (ALS) tells the nurse, "Sometimes I feel so frustrated. I can’t do anything without ...

Read more

NASM Flashcards

Which of the following is the process of getting oxygen from the environment to the tissues of the body? Diffusion ...

Read more

Unfinished tasks keep piling up?

Let us complete them for you. Quickly and professionally.

Check Price

Successful message
sending