Chapter 8 Classes and Objects: A Deeper Look

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

A programmer-defined constructor that has no arguments is called a(n) ________. a. empty constructor. b. no-argument constructor. c. default constructor. d. null constructor.

b. a no-argument constructor

The static method ________ of class String returns a formatted String. a. printf. b. format. c. formatString. d. toFormatedString.

b. format

Composition is sometimes referred to as a(n) ________. a. is-a relationship b. has-a relationship c. many-to-one relationship d. one-to-many relationship

b. has-a relationship

Which syntax imports all static members of class Math? a. import java.lang.Math.*. b. import static java.lang.Math.*. c. import static java.lang.Math. d. None of the above.

b. import static java.lang.Math.*

When implementing a method, use the class's set and get methods to access the class's ________ data. a. public. b. private. c. protected. d. All of the above.

b. private

What happens when this is used in a constructor's body to call another constructor of the same class if that call is not the first statement in the constructor? a. A compilation error occurs. b. A runtime error occurs. c. A logic error occurs. d. Nothing happens. The program compiles and runs.

a. A compilation error occurs

Which statement is false? a. The compiler always creates a default constructor for a class. b. If a class's constructors all require arguments and a program attempts to call a no-argument constructor to initialize an object of the class, a compilation error occurs. c. A constructor can be called with no arguments only if the class does not have any constructors or if the class has a public no-argument constructor. d. None of the above.

a. The compiler always creates a default constructor for the class.

Which of the following statements is true? a. Methods and instance variables can both be either public or private. b. Information hiding is achieved by restricting access to class members via keyword public. c. The private members of a class are directly accessible to the clients of a class. d. None of the above is true.

a. methods and instance variables can both be either public or private.

Which method returns an array of the enum's constants? a. values. b. getValues. c. constants. d. getConstants.

a. values

BigDecimal gives you control over how values are rounded. By default: a. all calculations are approximate and no rounding occurs. b. all calculations are approximate and rounding occurs. c. all calculations are exact and no rounding occurs. d. all calculations are exact and rounding occurs.

c. All calculations are exact and no rounding occurs.

Instance variables declared final do not or cannot: a. Cause syntax errors if used as a left-hand value. b. Be initialized. c. Be modified after they are initialized. d. None of the above.

c. Be modified after they are initialized.

When no access modifier is specified for a method or variable, the method or variable: a. Is public. b. Is private. c. Has package access. d. Is static.

c. Has package access.

Which of the following is false? a. Method finalize does not take parameters and has return type void. b. Memory leaks using Java are rare because of automatic garbage collection. c. Objects are marked for garbage collection by method finalize. d. The garbage collector reclaims unused memory.

c. Objects are marked for garbage collection by method finalize.

The _________ of a class are also called the public services or the public interface that the class provides to its clients. a. public constructors. b. public instance variables. c. public methods. d. All of the above.

c. Public methods

A constructor cannot: a. be overloaded. b. initialize variables to their defaults. c. specify return types or return values. d. have the same name as the class.

c. Specify return types or return values.

Which of the following class members should usually be private? a. Methods. b. Constructors. c. Variables (or fields). d. All of the above.

c. Variables (or fields)

Which statement is false? a. An enum declaration is a comma-separated list of enum constants and may optionally include other components of traditional classes, such as constructors, fields and methods. b. Any attempt to create an object of an enum type with operator new results in a compilation error. c. An enum constructor cannot be overloaded. d. enum constants are implicitly final and static.

c. an enum constructor cannot be overloaded.

Which statement is false? a. The actual data representation used within the class is of no concern to the class's clients. b. Clients generally care about what the class does but not how the class does it. c. Clients are usually involved in a class's implementation. d. Hiding the implementation reduces the possibility that clients will become dependent on class-implementation details.

c. client's are usually involved in a class' implementation.

Set methods are also commonly called ________ methods and get methods are also commonly called ________ methods. a. query, mutator. b. accessor, mutator. c. mutator, accessor. d. query, accessor.

c. mutator, accessor

Which of the following is false? a. A static method must be used to access private static instance variables. b. A static method has no this reference. c. A static method can be accessed even when no objects of its class have been instantiated. d. A static method can call instance methods directly.

d. A static method can call instance methods directly

Having a this reference allows: a. a method to refer explicitly to the instance variables and other methods of the object on which the method was called. b. a method to refer implicitly to the instance variables and other methods of the object on which the method was called. c. an object to reference itself. d. All of the above.

d. All of the above

Constructors: a. Initialize instance variables. b. When overloaded, can have identical argument lists. c. When overloaded, are selected by number, types and order of types of parameters. d. Both (a) and (c).

d. Both a and c

Static class variables: a. are final. b. are public. c. are private. d. are shared by all objects of a class.

d. Shared by all objects of a class.

Which of the following statements is false? a. An application that requires precise floating-point calculations such as those in financial applications should use class BigDecimal from package java.math. b. We use class NumberFormat for formatting numeric values as locale-specific strings. c. In the U.S, locale, the value 15467.82 would be formatted as "15,467.82", whereas in many European locales it would be formatted as "15.467,56". d. The BigDecimal method format receives a double argument and returns a BigDecimal object that represents the exact value specied.

d. The BigDecimal method format receives a double argument and returns a BigDecimal object that represents the exact value specified.

Which of the following statements is false? a. If a program uses multiple classes from the same package, these classes can access each other's package access members directly through references to objects of the appropriate classes, or in the case of static members, through the class name. b. Package access is rarely used. c. Classes in the same source file are part of the same package. d. Use the access modifier package to give a method or variable package access.

d. Use the access modifier package to give a method or variable package access

When must a program explicitly use the this reference? a. Accessing a private variable. b. Accessing a public variable. c. Accessing a local variable. d. Accessing an instance variable that is shadowed by a local variable

d. accessing an instance variable that is shadowed by a local variable.

Using public set methods helps provide data integrity if: a. The instance variables are public. b. The instance variables are private. c. The methods perform validity checking. d. Both b and c.

d. both b and c

A final field should also be declared ________ if it is initialized in its declaration. a. private. b. public. c. protected. d. static.

d. static


Ensembles d'études connexes

English Language Arts (11-B) Unit 1 Test Review

View Set

Ch 9 Maternal and Fetal Nutrition

View Set

Persuasion Exam 1 (Quiz Questions)

View Set

Oral comp example questions for SLP UWYO

View Set