java ch.6

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

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 c. methods b. relationships d. instances

C

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

A

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

A,B,D

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

B

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

D

An access specifier indicates how a class may be accessed.

True

After the header, the body of the method appears inside a set of __________. a. braces, { } c. brackets, [ ] b.parentheses, ( )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

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

A

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

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

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

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

A

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

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

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

False

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

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

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

B

A(n) __________ can be thought of as a blueprint that can be used to create a type of __________. a. object, class c. cookie, cake b. class, object d. object, 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 c. PrintWriter b.Stringd.Scanner

B

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

B

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 you work with a __________, you are using a storage location that holds a piece of data. a. primitive variable c. numeric literal b. reference variable 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

A constructor __________. a. always accepts two arguments c. has the return type of void b.has the same name as the classd.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

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 c. the values for each field b. the object's memory address 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 c. fields, methods b.fields, object namesd.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

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

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

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

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 c. java.util b. java.default 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 c. The constructor b. Abstraction 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

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

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

False

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

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


Kaugnay na mga set ng pag-aaral

Unit 7: Promulgated Addenda, Notices, and Other Forms TEST

View Set

The Economist September 8th-14th 2018 (412)

View Set

Economic Globalization Instruction/Quiz

View Set

sc cases quiz (engel v. vitale, wisconsin v. yoder, etc.)

View Set

Motion: Scalars, Vectors, and Linear Motion

View Set