Chapter 8 Quiz Flashcards

1
Q

When should a program explicitly use the this reference?

A

Accessing a field that is shadowed by a local variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A static class variables:

are public
are private
are shared by all objects of a class
cannot be accessed by any instance of the class

A

are shared by all objects of a class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

The import declaration import *; ________.

A

causes a compilation error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

When no access modifier is specified for a method or variable, the method or variable:

A

can be accessed by any program in its package

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

A class within a package must be declared public if

A

It will be used by classes that are not in the same package

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

T or F

A package is a group of nested classes and interfaces

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

T or F

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

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

T or F

Packages make it more difficult to reuse code

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

T or F

The garbage collector reclaims unused memory

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

T or F

The method finalize takes parameters

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

T or F

The method finalize uses a return type of void

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does the this method do

A

It allows an object to reference itself

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

In a class definition should a default constructor be declared private? Why or Why not?

A

A constructor should never be a private method as it would prevent the object from being instantiated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does declaring an instance variable final do?

A

Declaring an instance variable final means that the variable has a constant value that cannot be modified.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Imports all static members of a class

A

static import on demand

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

String class static method ______________ is similar to method System.out.printf, but return a formatted String rather than displaying a String in a command window.

A

format

17
Q

A method contains a local variable with the same name as one of it’s class fields, t he local variable is said to _______ the scope of the method’s scope.

A

Shadow

18
Q

The public methods of a class are known as

A

Public Interfaces or Public Services

19
Q

A(n) ________________ method is called implicitly when the objects appears in code where String is needed

A

ToString();

20
Q

A(n) _______________ declaration specifies one class to import.

A

single-type-import

21
Q

If a class declares constructors, the complier will not create a(n) ___________________

A

default constructor

22
Q

Get methods are commonly called

A

accessors methods or query methods

23
Q

If a class declares a constructor the complier will not create

A

a default constructor

24
Q

A ____________ method tests whether a condition is true or false

A

predicate