Java Chapter 6

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Which symbol indicates that a member is public in a UML diagram?

+

Which symbol indicates that a member is private a UML diagram?

-

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 ordNumber = 1234; double ordAmt = 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

__________ refers to combining data and code into a single object.

Encapsulation

A method that gets a value from a class's field but does not change it is known as a mutator method.

False

Instance methods should be declared static.

False

The public access specifier for a field indicates that the field may not be accessed by statements outside the class.

False

The term "default constructor" is applied to the first constructor written by the author of the class.

False

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

False

Java allows you to create objects of the __________ 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";

For the following code, which statement is not true? public class Circle { private double radius; public double x; private double y; }

The y field is available to code 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; }

The z field is available to code written outside the Sphere class.

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 is not an object. It is a description of an object.

True

A constructor is a method that is automatically called when an object is created.

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

An access specifier indicates how a class may be accessed.

True

An object can store data.

True

Instance methods do not have the key word static in their headers.

True

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

True

The java.lang package is automatically imported into all Java programs.

True

The term "no-arg constructor" is applied to any constructor that does not accept arguments.

True

When an object is passed as an argument to a method, the object's address is passed into the method's parameter variable.

True

What does the following UML diagram entry mean? + setHeight(h : double) : void

a public method with a parameter of data type double that does not return a value

The following statement is an example of __________. import java.util.*;

a wildcard import statement

The following statement is an example of __________. import java.util.Scanner;

an explicit import statement

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(n) __________ can be thought of as a blueprint that can be used to create a type of __________.

class, object

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 that multiple methods in the same class __________.

have the same name but different parameter lists

You should not define a class that is dependent on the values of other class fields __________.

in order to avoid having stale data

Another term for an object of a class is a(n) __________.

instance

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 __________ package is automatically imported into all Java programs.

java.lang

A reference variable stores a(n) __________.

memory address

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

methods

Most of the programming languages used today are __________.

object-oriented

A group of related classes is called a(n) __________.

package

A constructor is a method that __________.

performs initialization or setup operations

When you work with a __________, you are using a storage location that holds a piece of data.

primitive variable

Instance methods do not have the __________ key word in their headers.

static

Which of the following is not involved in identifying the classes to be used when developing an object-oriented application?

the code

The scope of a public instance field is __________.

the instance methods and methods outside the class

The scope of a private instance field is __________.

the instance methods of the same class

A UML diagram does not contain __________.

the object names

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

A class's responsibilities include __________.

the things a class is responsible for knowing the things a class is responsible for doing both of these

To indicate the data type of a variable in a UML diagram, you enter __________.

the variable name followed by a colon and the data type

Two or more methods in a class may have the same name as long as __________.

they have different parameter lists

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


Ensembles d'études connexes

Life Insurance Final Exam Questions Part 1

View Set

Chapter 9: Kings and Prophets 1: The Early Monarchy

View Set

Europe and Russia Map Lab Challenge #4

View Set

IB Bio - 7.2 Transcription and Gene Expression

View Set