Sunteți pe pagina 1din 5

Java How to Program, 5/e Test Item File 1 of 5

Chapter 8

Section 8.1

8.1 Q1: Object-Oriented Programming encapsulates:


a.Data and methods.
b.Information hiding.
c.Classes.
d.Adjectives
ANS: a. Data and methods

Section 8.2

8.2 Q1: If class A extends B, then:


a.Class A is the base class.
b.Class A is the superclass.
c.Class A inherits from class B.
d.Class B is the derived class.
ANS: c. Class A inherits from class B. Class B is the base class or superclass. Class A is the derived class or
subclass.

8.2 Q2: Constructors:


a.Have the same name as the class.
b.May not specify a return type.
c.Initialize objects of a class.
d.All of the above.
ANS: d. All of the above.

Section 8.3

8.3 Q1: An instance variable is hidden in the scope of a method when


a.The instance variable has the same name as the method.
b.The instance variable has the same name as a local variable in the method.
c.The instance variable has the same name as the class.
d.The instance variable has the same name as the file.
ANS: b. The instance variable has the same name as a local variable in the method.

8.3 Q2: Which of the following statements is true?


a.Within a class’s scope, class members are accessible to all of that class’s methods, but cannot be referenced
directly by name.
b.It is a syntax error if a method declares a local variable with the same name as a variable declared in the
method’s enclosing class.
c.Variables declared in a method are known only to that method.
d.None of the above.
ANS: c. Variables declared in method are know only to that method.

Section 8.4

8.4 Q1: Which of the following should usually be private?


a.Methods.
b.Constructors.
c.Variables (or fields).
d.All of the above.
ANS: c. Variables (or fields).

8.4 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 client of a class.
d.None of the above is true.
ANS: a. Methods and instance variables can both be either public or private.

© Copyright 2003 by Deitel & Associates, Inc. and Prentice Hall. All Rights Reserved.
Java How to Program, 5/e Test Item File 2 of 5

Section 8.5:

8.5 Q1: When should a program explicitly use the this reference:
a.Accessing a private variable.
b.Accessing a public variable.
c.Accessing a local variable.
d.Accessing a field that is shadowed by a local variable.
ANS: c. Accessing a field that is shadowed by a local variable.

8.5 Q2: Having a this reference allows:


a.A method 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.
ANS: d. All of the above.

Section 8.6

8.6 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.
ANS: c. Specify return types or return values.

8.6 Q2: Which of the following will be used to create an instance of a class if the programmer does not define a
constructor?
a.A default constructor.
b.An overloaded constructor.
c.The Object class constructor with the name of the desired class passed in as an argument.
d.If no constructor is written, then one isn’t needed.
ANS: a. A default constructor.

Section 8.7

8.7 Q1: Constructors:


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

8.7 Q2: A well-designed group of constructors:


a.Guarantee the object is created in a consistent state.
b.May call common methods.
c.Allows the class's user flexibility in specifying some or all of the initial instance variable values.
d.All of the above.
ANS d. All of the above.

Section 8.8

8.8 Q1: Not using set and get methods is:


a.A syntax error.
b.A logic error.
c.Not good program design.
d.None of the above.
ANS: c. Not good program design.

© Copyright 2003 by Deitel & Associates, Inc. and Prentice Hall. All Rights Reserved.
Java How to Program, 5/e Test Item File 3 of 5

8.8 Q2: Using public set methods provides data integrity if:
a.The instance variables are public.
b.The instance variables are private.
c.The programmer provides validity checking.
d.Both b and c.
ANS: d. Both b and c.

Section 8.9

8.9 Q1: Composition:


a.Is a form of software reuse.
b.Is using an object reference as a class member.
c.Is a good design practice.
d.All of the above.
ANS: d. All of the above.

Section 8.10

8.10 Q1: Which of the following is not true?


a.Finalizer methods typically return resources to the system.
b.Memory leaks using Java are rare because of garbage collection.
c.Objects are marked for garbage collection by the finalizer.
d.The garbage collector reclaims unused memory.
ANS: c. Objects are marked for garbage collection by the finalizer. Object are marked for garbage collection when
there are no more references to the object

Section 8.11

8.11 Q1: Static class variables:


a.Are final.
b.Are public.
c.Are private.
d.Are shared by all objects of a class.
ANS: d. Are shared by all objects of a class.

8.11 Q2: Which of the following is not true?


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.
ANS: d. A static method can call instance methods directly.

Section 8.12

8.12 Q1: Instance variables declared final do not or cannot:


a.Use the principle of least privilege.
b.Be initialized.
c.Be modified.
d.Cause syntax errors if used as a left-hand value.
ANS: c. Be modified.

Section 8.13

8.13 Q1: A package is:


a.A directory structure used to organize classes and interfaces.

© Copyright 2003 by Deitel & Associates, Inc. and Prentice Hall. All Rights Reserved.
Java How to Program, 5/e Test Item File 4 of 5

b.A mechanism for software reuse.


c.A group of related classes and interfaces.
d.All of the above.
ANS: d. All of the above.

8.13 Q2: A class within a package must be declared public if


a.It will only be used by other classes in the same package.
b.It will be used by classes that are not in the same package.
c.It is in the same directory as the other classes in the package.
d.It has a unique name.
ANS: b. It will be used by classes that are not in the same package. Classes outside the package cannot use a
class if the class is not declared public.

8.13 Q3: Consider the statement


package com.deitel.jhtp5.ch08;
a.The statement declares a package that exists at deitel.com.
b.The statement uses the Sun Microsystems convention of package naming.
c.The statement specifies a package that can be imported using: import com.deitel.ch08.
d.The statement will generate a compile time error.
ANS: b. The statement uses the Sun Microsystems convention of package naming.

Section 8.14
8.14 Q1: When no member 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.
ANS: c. Has package access.

Section 8.15

8.15 Q1: Java programmers do not focus on:


a.Crafting new classes and reusing existing classes.
b.Understanding class library implementations
c.Carefully testing classes they design.
d.Carefully documenting classes they design.
ANS: b. Understanding class library implementations. Information hiding and well-defined interfaces free Java
programmers from needing to understand existing class library implementations.

8.15 Q2: Which of the following does not contribute to improved software reusability?
a.Quickly creating new class libraries without testing them thoroughly.
b.Licensing schemes and protection mechanisms.
c.Descriptions of classes that allow programmers to determine whether a class fits their needs.
d.Cataloging schemes and browsing mechanisms.
ANS: Quickly creating new class libraries without testing them thoroughly.

Section 8.16

8.16 Q1: Abstract Data Types:


a.Elevate the importance of data.
b.Are only approximation or models of real-world concepts and behaviors.
c.Capture tow notions, data representation and operations.
d.All of the above.
ANS: d. All of the above.

8.16 Q2: The term information hiding refers to:


a.public methods.
b.Hiding implementation details from clients of a class.
c.Accessing static class members.
© Copyright 2003 by Deitel & Associates, Inc. and Prentice Hall. All Rights Reserved.
Java How to Program, 5/e Test Item File 5 of 5

d.The process of releasing an object for garbage collection.


ANS: b. Hiding implementation details from clients of a class.

© Copyright 2003 by Deitel & Associates, Inc. and Prentice Hall. All Rights Reserved.

S-ar putea să vă placă și