Java Ch. 6 Quiz

25 July 2022
4.7 (114 reviews)
30 test answers

Unlock all answers in this set

Unlock answers (26)
question
Quite often you have to use this statement to make a group of classes available to a program. a. assume b. import c. link d. use
answer
b. import
question
It is common practice in object-oriented programming to make all of a class's: a. fields and methods public b. fields public c. methods private d. fields private
answer
d. fields private
question
Methods that operate on an object's fields are called: a. instance variables b. instance methods c. private methods d. public methods
answer
b. instance methods
question
Java allows you to create objects of this class in the same way you would create primitive variables. a. String b. Scanner c. PrintWriter d. Random
answer
a. String
question
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. using the private access specifier on the class fields
question
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. radius is not available to code written outside the Circle class. b. radius, x, y, and z are called members of the Circle class. c. z is available to code that is written outside the Circle class. d. x is available to code that is written outside the Circle class.
answer
c. z is available to code that is written outside the Circle class.
question
After the header, the body of the method appears inside a set of: a. braces, {} b. double quotes, "" c. brackets, [] d. parentheses, ()
answer
a. braces, {}
question
Look at the following statement. import java.util.Scanner; This is an example of a. unconditional import b. an explicit import c. conditional import d. a wildcard import
answer
b. an explicit import
question
In UML diagrams, this symbol indicates that a member is private: a. * b. + c. - d. #
answer
c. -
question
Another term for an object of a class is: a. method b. instance c. access specifier d. member
answer
b. instance
question
For the following code, which statement is NOT true? public class Circle { private double radius; public double x; private double y; } a. y 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. x is available to code that is written outside the Circle class.
answer
a. y is available to code that is written outside the Circle class.
question
Class objects normally have ________ that perform useful operations on their data, but primitive variables do not. a. instances b. methods c. relationships d. fields
answer
b. methods
question
The scope of a public instance field is: a. inside the class, but not inside any method b. only the class in which it is defined c. inside the parentheses of a method header d. the instance methods and methods outside the class
answer
d. the instance methods and methods outside the class
question
In UML diagrams, this symbol indicates that a member is public. a. - b. / c. + d. @
answer
c. +
question
Look at the following statement. import java.util.*; This is an example of: a. unconditional import b. conditional import c. a wildcard import d. an explicit import
answer
c. a wildcard import
question
In the cookie cutter metaphor, think of the ________ as a cookie cutter and ________ as the cookies. a. attribute; methods b. class; fields c. class; objects d. object; classes
answer
c. class; objects
question
A UML diagram does not contain: a. the method names b. the class name c. object names d. the field names
answer
c. object names
question
In a UML diagram to indicate the data type of a variable enter: a. the class name followed by the variable name followed by the data type b. the data type followed by the variable name c. the variable name followed by a colon and the data type d. the variable name followed by the data type
answer
c. the variable name followed by a colon and the data type
question
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 { 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 = $%,.2fn", 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. 522.00
question
One or more objects may be created from a(n): a. class b. instance c. field d. method
answer
a. class
question
A constructor is a method that: a. never receives any arguments. b. returns an object of the class. c. with the name ClassName.constructor. d. performs initialization or setup operations.
answer
d. performs initialization or setup operations.
question
Most programming languages that are in use today are: a. object-oriented b. logic c. functional d. procedural
answer
a. object-oriented
question
A class specifies the ________ and ________ that a particular type of object has. a. fields; object names b. fields; methods c. relationships; methods d. relationships; object names
answer
b. fields; methods
question
Instance methods do not have this key word in their headers: a. private b. public c. protected d. static
answer
d. static
question
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 = $%,.2fn", 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. There is no value because the object order has not been created.
question
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. have the same name, but different parameter lists
question
A constructor: a. always has an access specifier of private b. has the same name as the class c. always accepts two arguments d. has return type of void
answer
b. has the same name as the class
question
The following package is automatically imported into all Java programs. a. java.default b. java.util c. java.lang d. java.java
answer
c. java.lang
question
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 the things a class is responsible for doing and the things a class is responsible for knowing d. neither the things a class is responsible for doing nor the things a class is responsible for knowing
answer
c. both the things a class is responsible for doing and the things a class is responsible for knowing
question
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. object name; attributes or fields; methods b. class name; attributes or fields; methods c. object name; methods; attributes or fields d. class name; object name; methods
answer
b. class name; attributes or fields; methods