Docsity

ABSOLUTE JAVA 6TH EDITION STUDY GUIDE WITH QUESTIONS AND SOLUTIONS, Exams of Java Programming

Toggle sidebar
bg1
ABSOLUTE JAVA 6TH EDITION STUDY GUIDE WITH QUESTIONS
AND SOLUTIONS
Question 1.
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 2.
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 3.
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 4.
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
pf3
pf4
pf5

Partial preview of the text

Download ABSOLUTE JAVA 6TH EDITION STUDY GUIDE WITH QUESTIONS AND SOLUTIONS and more Exams Java Programming in PDF only on Docsity!

ABSOLUTE JAVA 6TH EDITION STUDY GUIDE WITH QUESTIONS

AND SOLUTIONS

Question 1.

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 2.

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 3.

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 4.

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

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 6.

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

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 8.

In UML diagrams, this symbol indicates that a member is private: a. * b. + c. - d. #.

Answer: c. -

Question 9.

Another term for an object of a class is: a. method b. instance c. access specifier d. member.

Answer: b. instance

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 16.

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 17.

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

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 = $%,.2f\n", finalAmount); a. 528. b. 580. c. 522. d. There is no value because the object order has not been created..

Answer: c. 522.

One or more objects may be created from a(n): a. class b. instance c. field d. method.

Answer: a. class

Question 20.

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 21.

Most programming languages that are in use today are: a. object-oriented b. logic c. functional d. procedural.

Answer: a. object-oriented

Question 22.

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 23.

Instance methods do not have this key word in their headers: a. private b. public c. protected d. static.

Answer: d. static

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 29.

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