Java Chapter 6

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

After the header, the body of the method appears inside a set of __________. a. braces, { } b. parentheses, ( ) c. brackets, [ ] d. double quotes, " "

A

For the following code, which statement is not true? public class Circle { private double radius; public double x; private double y; } a. The y field is available to code written outside the Circle class. b. The radius field is not available to code written outside the Circle class. c. The radius, x, and y fields are members of the Circle class. d. The x field is available to code that is written outside the Circle class.

A

For the following code, which statement is not true? public class Circle { private double radius; public double x; private double y; } a. The z field is available to code written outside the Sphere class. b. The radius field is not available to code written outside the Sphere class. c. The radius, x, y, and z fields are members of the Sphere class. d. The x field is available to code that is written outside the Sphere class.

A

It is common practice in object-oriented programming to make all of a class's __________. a. fields private b. methods private c. fields public d. fields and methods public

A

Methods that operate on an object's fields are called __________. a) instance methods b) instance variables c) private methods d) public methods

A

The following statement is an example of __________. import java.util.Scanner; a. an explicit import statement b. an unconditional import statement c. a wildcard import statement d. a conditional import statement

A

The scope of a private instance field is __________. a. the instance methods of the same class b. inside the class but not inside any method in that class c. inside the parentheses of a method header d. the method in which it is defined

A

What does the following UML diagram entry mean? + setHeight(h : double) : void a. a public method with a parameter of data type double that does not return a value b. a private field called setHeight that is a double data type c. a private method with no parameters that returns a double data type d. a public field called setHeight that is a double data type

A

When an object is created, the attributes associated with the object are called __________. a) instance fields b) class instances c) instance methods d) fixed attributes

A

When you work with a __________, you are using a storage location that holds a piece of data. a. primitive variable b. reference variable c. numeric literal d. binary number

A

Which of the following statements will create a reference, str, to the String "Hello, World"? a. String str = "Hello, World"; b. string str = "Hello, World"; c. String str = new "Hello, World"; d. str = "Hello, World";

A

Which symbol indicates that a member is private a UML diagram? a. - b. * c. # d. +

A

Select all that apply. Which of the following are classes from the Java API? a. Scanner b. Random c. Package d. PrintWriter

A,B,D

A constructor __________. a. always accepts two arguments b. has the same name as the class c. has the return type of void d. always has a private access specifier

B

A group of related classes is called a(n) __________. a) archive c) collection b) package d) attachment

B

A reference variable stores a(n) __________. a. binary encoded decimal b. memory address c. object d. string

B

A(n) __________ can be thought of as a blueprint that can be used to create a type of __________. a. object, class b. class, object c. cookie, cake d. object, method

B

Another term for an object of a class is a(n) __________. a. access specifier b. instance c. member d. method

B

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

B

Java allows you to create objects of the __________ class in the same way you would create primitive variables. a. Random b. String c. PrintWriter d. Scanner

B

Methods that operate on an object's fields are called __________. a. instance variables b. instance methods c. public methods d. private methods

B

To indicate the data type of a variable in a UML diagram, you enter __________. a. the variable name followed by the data type b. the variable name followed by a colon and the data type c. the class name followed by the variable name followed by the data type d. the data type followed by the variable name

B

Two or more methods in a class may have the same name as long as __________. a. they have different return types b. they have different parameter lists c. they have different return types but the same parameter list d. You cannot have two methods with the same name.

B

When an object is passed as an argument to a method, what is passed into the method's parameter variable? a. the class name b. the object's memory address c. the values for each field d. the method names

B

Which of the following is not involved in identifying the classes to be used when developing an object-oriented application? a. a description of the problem domain b. the code c. a refined list of nouns that include only those relevant to the problem d. all the nouns are identified

B

A class specifies the __________ and __________ that a particular type of object has. a. relationships, methods b. fields, object names c. fields, methods d. relationships, object names

C

A class's responsibilities include __________. a) the things a class is responsible for knowing b) the things a class is responsible for doing c) both of these d) neither of these

C

A constructor __________. a. always accepts two arguments b. has the return type of void c. has the same name as the class d. always has a private access specifier

C

A constructor is a method that __________. a. returns an object of the class b. never receives any arguments c. performs initialization or setup operations d. removes the object from memory

C

Class objects normally have __________ that perform useful operations on their data, but primitive variables do not. a) fields b) relationships c) methods d) instances

C

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 fields d) using the private access specifier on the class definition

C

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); } } a. 528.00 b. 580.00 c. 522.00 d. There is no value because the object, order, has not been created.

C

Most of the programming languages used today are __________. a. procedural b. top-down c. object-oriented d. functional

C

Overloading means that 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

C

The following statement is an example of __________. import java.util.*; a. an explicit import statement b. an unconditional import statement c. a wildcard import statement d. a conditional import statement

C

You should not define a class that is dependent on the values of other class fields __________. a. in order to keep it current b. because it is redundant c. in order to avoid having stale data d. because it should be defined in another class

C

A UML diagram does not contain __________. a. the class name b. the method names c. the field names d. the object names

D

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

D

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

D

The __________ package is automatically imported into all Java programs. a. java.java b. java.default c. java.util d. java.lang

D

The scope of a public instance field is __________. a. only the class in which it is defined b. inside the class but not inside any method c. inside the parentheses of a method header d. the instance methods and methods outside the class

D

Which symbol indicates that a member is public in a UML diagram? a. - b. * c. # d. +

D

__________ refers to combining data and code into a single object. a. Data hiding b. Abstraction c. The constructor d. Encapsulation

D

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

F

Instance methods should be declared static.

F

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

F

The term "default constructor" is applied to the first constructor written by the author of 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

A class is not an object. It is 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 a class may be accessed.

T

An object can store data.

T

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

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

T

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

T

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

T


Ensembles d'études connexes

issues and wellness tri 3 nutrition

View Set

Mental Health Unit I: questions from Quizlet and NCLEX questions from Online Resources

View Set

Strategic management: Q7 The resource-based view of the firm

View Set

Improving Vocabulary Skills Chapter 20

View Set

Unit 1. Electrical Test Equipment & Testing Components (SA)

View Set

Anatomy Unit 2: Skeletal System and Muscle Tissue

View Set

USMLE Step 1 Biochemistry: Genetics

View Set

Chapter 21 Microbiology Learnsmart

View Set

Combo with "Biology Exam #2" and 1 other

View Set

Chapter 17 Patho taken from http://thepoint.lww.com/Book LEVEL 3 MASTERY

View Set

Chapter 02: Research Questions, Hypotheses, and Clinical Questions

View Set