Chapter 5 Flashcards
- Which the following statements about the base keyword is false?
a. A constructor can use at most one base statement.
b. A constructor cannot use both a base statement and a this statement.
c. The base keyword lets a constructor invoke a different constructor in the same class.
d. If a constructor uses a base statement, its code is executed after the invoked constructor is executed.
c. The base keyword lets a constructor invoke a different constructor in the same class.
- Which the following statements about the this keyword is false?
a. A constructor can use at most one this statement.
b. A constructor can use a this statement and a base statement if the base statement comes first.
c. The this keyword lets a constructor invoke a different constructor in the same class.
d. If a constructor uses a this statement, its code is executed after the invoked constructor is executed.
b. A constructor can use a this statement and a base statement if the base statement comes first.
- Suppose you have defined the House and Boat classes and you want to make a HouseBoat class that inherits from both House and Boat. Which of the following approaches would not work?
a. Make HouseBoat inherit from both House and Boat.
b. Make HouseBoat inherit from House and implement an IBoat interface.
c. Make HouseBoat inherit from Boat and implement an IHouse interface.
d. Make HouseBoat implement both IHouse and IBoat interfaces.
a. Make HouseBoat inherit from both House and Boat.
- Suppose the HouseBoat class implements the IHouse interface implicitly and the IBoat interface explicitly. Which of the following statements is false?
a. The code can use a HouseBoat object to access its IHouse members.
b. The code can use a HouseBoat object to access its IBoat members.
c. The code can treat a HouseBoat object as an IHouse to access its IHouse members.
d. The code can treat a HouseBoat object as an IBoat to access its IBoat members.
b. The code can use a HouseBoat object to access its IBoat members.
- Which of the following is not a good use of interfaces?
a. To simulate multiple inheritance.
b. To allow the code to treat objects that implement the interface polymorphically as if they were of the interface’s “class.”
c. To allow the program to treat objects from unrelated classes in a uniform way.
d. To reuse the code defined by the interface.
d. To reuse the code defined by the interface.
- Suppose you want to make a Recipe class to store cooking recipes and you want to sort the Recipes by the MainIngredient property. In that case, which of the following interfaces would probably be most useful?
a. IDisposable
b. IComparable
c. IComparer
d. ISortable
b. IComparable
- Suppose you want to sort the Recipe class in question 6 by any of the properties MainIngredient, TotalTime, or CostPerPerson. In that case, which of the following interfaces would probably be most useful?
a. IDisposable
b. IComparable
c. IComparer
d. ISortable
c. IComparer
- Which of the following statements is true?
a. A class can inherit from at most one class and implement at most one interface.
b. A class can inherit from any number classes and implement any number of interfaces.
c. A class can inherit from at most one class and implement any number of interfaces.
d. A class can inherit from any number of classes and implement at most one interface.
c. A class can inherit from at most one class and implement any number of interfaces.
- A program can use the IEnumerable and IEnumerator interfaces to do which of the following?
a. Use MoveNext and Reset to move through a list of objects.
b. Use foreach to move through a list of objects.
c. Move through a list of objects by index.
d. Use the yield return statement to make a list of objects for iteration.
a. Use MoveNext and Reset to move through a list of objects.
- Which of the following statements about garbage collection is false?
a. In general, you can’t tell when the GC will perform garbage collection.
b. It is possible for a program to run without ever performing garbage collection.
c. An object’s Dispose method can call GC.SuppressFinalize to prevent the GC from calling the object’s destructor.
d. Before destroying an object, the GC calls its Dispose method.
d. Before destroying an object, the GC calls its Dispose method.
- Which of the following statements about destructors is false?
a. Destructors are called automatically.
b. Destructors cannot assume that other managed objects exist while they are executing.
c. Destructors are inherited.
d. Destructors cannot be overloaded.
c. Destructors are inherited.
- If a class implements IDisposable, its Dispose method should do which of the following?
a. Free managed resources.
b. Free unmanaged resources.
c. Call GC.SuppressFinalize.
d. All of the above.
d. All of the above.
- If a class has managed resources and no unmanaged resources, it should do which of the following?
a. Implement IDisposable and provide a destructor.
b. Implement IDisposable and not provide a destructor.
c. Not implement IDisposable and provide a destructor.
d. Not implement IDisposable and not provide a destructor.
b. Implement IDisposable and not provide a destructor.
- If a class has unmanaged resources and no managed resources, it should do which of the following?
a. Implement IDisposable and provide a destructor.
b. Implement IDisposable and not provide a destructor.
c. Not implement IDisposable and provide a destructor.
d. Not implement IDisposable and not provide a destructor.
a. Implement IDisposable and provide a destructor.
E1. What keyword do you use to make a constructor invoke a base class constructor?
a. base
b. mybase
c. MyBase
d. this
e. parent
f. constructor
a. Implement IDisposable.