Deck 8: Classes and Objects: a Deeper Look

Full screen (f)
exit full mode
Question
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).
Use Space or
up arrow
down arrow
to flip the card.
Question
Which method returns an array of the enum's constants?

A) values.
B) getValues.
C) constants.
D) getConstants.
Question
Which of the following class members should usually be private?

A) Methods.
B) Constructors.
C) Variables (or fields).
D) All of the above.
Question
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.
Question
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.
Question
Static class variables:

A) are final.
B) are public.
C) are private.
D) are shared by all objects of a class.
Question
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.
Question
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.
Question
The static method ________ of class String returns a formatted String.

A) printf.
B) format.
C) formatString.
D) toFormatedString.
Question
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.
Question
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.
Question
Using public set methods helps provide data integrity if:

A) The instance variables are public.
B) The instance variables are private.
C)
C) The methods perform validity checking.
D) Both b and
Question
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.
Question
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.
Question
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.
Question
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.
Question
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.
Question
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.
Question
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
Question
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.
Question
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.
Question
A final field should also be declared ________ if it is initialized in its declaration.

A) private.
B) public.
C) protected.
D) static.
Question
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.
Question
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.
Question
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.
Question
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.
Question
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.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/27
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 8: Classes and Objects: a Deeper Look
1
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
2
Which method returns an array of the enum's constants?

A) values.
B) getValues.
C) constants.
D) getConstants.
A
3
Which of the following class members should usually be private?

A) Methods.
B) Constructors.
C) Variables (or fields).
D) All of the above.
C
4
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.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
5
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.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
6
Static class variables:

A) are final.
B) are public.
C) are private.
D) are shared by all objects of a class.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
7
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.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
8
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.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
9
The static method ________ of class String returns a formatted String.

A) printf.
B) format.
C) formatString.
D) toFormatedString.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
10
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.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
11
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.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
12
Using public set methods helps provide data integrity if:

A) The instance variables are public.
B) The instance variables are private.
C)
C) The methods perform validity checking.
D) Both b and
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
13
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.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
14
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.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
15
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.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
16
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.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
17
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.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
18
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.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
19
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
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
20
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.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
21
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.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
22
A final field should also be declared ________ if it is initialized in its declaration.

A) private.
B) public.
C) protected.
D) static.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
23
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.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
24
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.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
25
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.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
26
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.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
27
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.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 27 flashcards in this deck.