java chapter 6

¡Supera tus tareas y exámenes ahora con Quizwiz!

In UML diagrams, this symbol indicates that a member is public.

+

In UML diagrams, this symbol indicates that a member is private:

-

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

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.printf("Final order amount = $%,.2f\n", finalAmount); } }

522.00

What is stored by a reference variable?

A memory address

Which of the following are classes from the Java API?

All of the above

This refers to the combining of data and code into a single object.

Encapsulation

The term default constructor is applied to the first constructor written by the author of a class. True or False?

False

When a local variable in an instance method has the same name as an instance field, the instance field hides the local variable. True or False?

False

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); } } 522.0

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); } } no value

Which of the following statements will create a reference, str, to the String, Hello

String str = Hello

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); } }

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

A class in not an object, but a description of an object. True or False?

True

A constructor is a method that is automatically called when an object is created. True or False?

True

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. True or False?

True

An access specifier indicates how the class may be accessed. True or False?

True

An object can store data. True or False?

True

Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter variable True or False?

True

The java.lang package is automatically imported into all Java programs. True or False?

True

The term no-arg constructor is applied to any constructor that does not accept arguments. True or False?

True

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

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

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

In the cookie cutter metaphor, think of the ________ as a cookie cutter and ________ as the cookies.

class; objects

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

fields private

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

fields; methods

A constructor:

has the same name as the class

Overloading means multiple methods in the same class:

have the same name, but different parameter lists

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

Methods that operate on an object's fields are called:

instance methods

The following package is automatically imported into all Java programs.

java.lang

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

methods

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

A constructor is a method that:

performs initialization or setup operations.

When you are working with a ________, you are using a storage location that holds a piece of data.

primitive variable

Instance methods do not have this key word in their headers:

static

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

In a UML diagram to indicate the data type of a variable enter:

the variable name followed by a colon and the data type

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


Conjuntos de estudio relacionados

Prep U for Brunner and Suddarth's Textbook of Medical Surgical Nursing, 13th Edition Chapter 65: Assessment of Neurologic Function

View Set

Pharmacology Chapter 9 Antibiotics

View Set