Java CH 6
Instance methods do not have the key word static in their headers.
T
Which of the following are classes from the Java API?
a. Scanner b. Random c. PrintWriter
It is common practice in object-oriented programming to make all of a class's
fields private
A constructor:
has the same name as the class
Quite often you have to use this statement to make a group of classes available to a program
import
When an object is created, the attributes associated with the object are called:
instance fields
The following package is automatically imported into all Java programs.
java.lang
A UML diagram does not contain:
object names
Most programming languages that are in use today are:
object-oriented
This is a group of related classes.
package
When you are working with a ____________, you are using a storage location that holds a piece of data.
primitive variable
The scope of a private instance field is:
the instance methods of the same class
When an object is passed as an argument to a method, what is passed into the method's parameter variable?
the object's memory address
Two or more methods in a class may have the same name as long as:
they have different parameter lists
In UML diagrams, this symbol indicates that a member is public.
+
In UML diagrams, this symbol indicates that a member is private:
-
What is stored by a reference variable?
A memory address
The java.lang package is automatically imported into all Java programs.
T
Instance methods do not have this key word in their headers:
static
This refers to the combining of data and code into a single object.
Encapsulation
Instance methods should be declared static.
F
A method that gets a value from a class's field but does not change it is known as a mutator method.
F
The public access specifier for a field indicates that the attribute may not be accessed by statements outside the class.
F
When a local variable in an instance method has the same name as an instance field, the instance field hides the local variable.
F
After the header, the body of the method appears inside a set of:
braces, {}
One or more objects may be created from a(n):
class
A class specifies the ________ and ________ that a particular type of object has.
fields; methods
A constructor is a method that:
performs initialization or setup operations.
The scope of a public instance field is:
the instance methods and methods outside the class
In a UML diagram to indicate the data type of a variable enter:
the variable name followed by a colon and the data type
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 _______.
class name; attributes or fields; methods
Which of the following statements will create a reference, str, to the string, "Hello, world"? String str = new String("Hello, world"); String str = "Hello, world";
1 and 2
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.println("Final order amount = $" + } } finalAmount); } }
522.00
The term "default constructor" is applied to the first constructor written by the author of a class.
F
Java allows you to create objects of this class in the same way you would create primitive variables.
String
Which of the following statements will create a reference, str, to the String, "Hello, World"?
String str = "Hello, World";
A class in not an object, but a description of an object.
T
A constructor is a method that is automatically called when an object is created.
T
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.
T
An access specifier indicates how the class may be accessed.
T
An object can store data.
T
Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter variable.
T
The term "no-arg constructor" is applied to any constructor that does not accept arguments.
T
Which of the following is not involved in finding the classes when developing an object-oriented application?
Write the code.
Look at the following statement. import java.util.*; This is an example of:
a wildcard import
Look at the following statement. import java.util.Scanner; This is an example of
an explicit import
A class's responsibilities include:
both A and B
In the cookie cutter metaphor, think of the ________ as a cookie cutter and ________ as the cookies.
class; objects
Overloading means multiple methods in the same class
have the same name, but different parameter lists
You should not define a class field that is dependent upon the values of other class fields:
in order to avoid having stale data
Another term for an object of a class is
instance
Methods that operate on an object's fields are called:
instance methods
Class objects normally have __________ that perform useful operations on their data, but primitive variables do not.
methods
What does the following UML diagram entry mean? + setHeight(h : double) : void
this is a public method with a parameter of data type double and does not return a value
Data hiding, which means that critical data stored inside the object is protected from code outside the object, is accomplished in Java by:
using the private access specifier on the class fields
For the following code, which statement is not true? public class Circle { private double radius; public double x; private double y; }
y is available to code that is written outside the Circle class.
For the following code, which statement is not true? public class Sphere { private double radius; public double x; private double y; private double z; }
z is available to code that is written outside the circle class.