Programming Languages Chapter 08 What happens when this is used in a constructor

subject Type Homework Help
subject Pages 5
subject Words 1541
subject Authors Harvey Deitel, Paul Deitel

Unlock document.

This document is partially blurred.
Unlock all pages and 1 million more documents.
Get Access
page-pf1
Chapter 8 Classes and Objects: A Deeper Look
Section 8.2 Time Class Case Sudy
8.2 Q1: 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.
8.2 Q2: The static method ________ of class String returns a formatted String.
a. printf.
b. format.
c. formatString.
d. toFormatedString.
8.2 Q3: 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.
8.3 Q1: Which of the following class members should usually be private?
a. Methods.
b. Constructors.
c. Variables (or fields).
d. All of the above.
8.3 Q2: 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.
8.4 Q1: 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.
page-pf2
8.4 Q2: 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.
8.5 Q1: 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.
8.5 Q2: 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).
8.5 Q3: 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.
8.5 Q4: 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.
8.5 Q5: 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.
page-pf3
8.6 Q1: Which statement is false?
a. The compiler always creates a default constructor for a class.
b. If a classs 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.
8.7 Q1: 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.
8.7 Q2: 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.
8.8 Q1: 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
8.9 Q1: 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.
8.9 Q2: Which method returns an array of the enum’s constants?
a. values.
b. getValues.
c. constants.
d. getConstants.
page-pf4
8.10 Q1: 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.
8.11 Q1: Static class variables:
a. are final.
b. are public.
c. are private.
d. are shared by all objects of a class.
8.11 Q2: 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.
8.12 Q1: 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.
8.13 Q1: 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.
8.13 Q2: A final field should also be declared ________ if it is initialized in its declaration.
a. private.
b. public.
c. protected.
d. static.
page-pf5
8.14 Q1: 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.
8.14 Q2: 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.
8.15 Q1: 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.
8.15 Q2: 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.

Trusted by Thousands of
Students

Here are what students say about us.

Copyright ©2022 All rights reserved. | CoursePaper is not sponsored or endorsed by any college or university.