c. The base keyword lets a constructor invoke a different constructor in the same class.
b. A constructor can use a this statement and a base statement if the base statement comes first.
a. Make HouseBoat inherit from both House and Boat.
b. The code can use a HouseBoat object to access its IBoat members.
d. To reuse the code defined by the interface.
b. IComparable
c. IComparer
c. A class can inherit from at most one class and implement any number of interfaces.
a. Use MoveNext and Reset to move through a list of objects.
d. Before destroying an object, the GC calls its Dispose method.
c. Destructors are inherited.
d. All of the above.
b. 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.
E2. What keyword do you use to make a constructor invoke a different constructor in the same class?
a. base
b. mybase
c. MyBase
d. this
e. parent
f. constructor
d. this
E3. Suppose the Person class provides two constructors that do different things and you derive the Student class from Person. Suppose you want to make a Student constructor that does what both of the Person constructors do. Which of the following strategies would give you this result?
a. Use multiple base clauses.
b. Move the tasks performed by the Person constructors into methods and invoke them from the Student constructor.
c. Make a third Person constructor that invokes the other two Person constructors. Then have the Student constructor invoke the new Person constructor.
d. Move the tasks performed by the Person constructors into methods, and make a third Person constructor that invokes those methods. Then have the Student constructor invoke the new Person constructor.
b. Move the tasks performed by the Person constructors into methods and invoke them from the Student constructor.
d. Move the tasks performed by the Person constructors into methods, and make a third Person constructor that invokes those methods. Then have the Student constructor invoke the new Person constructor.
E4. Suppose you have created Boat and Car classes, and you want to make an AquaticCar class. Which of the following approaches would work?
a. Make AquaticCar inherit from both Boat and Car.
b. Make AquaticCar inherit from Boat and implement an ICar interface.
c. Make AquaticCar inherit from Car and implement an IBoat interface.
d. Make AquaticCar implement ICar and IBoat interfaces.
b. Make AquaticCar inherit from Boat and implement an ICar interface.
c. Make AquaticCar inherit from Car and implement an IBoat interface.
d. Make AquaticCar implement ICar and IBoat interfaces.
E5. Suppose you have created a Boat class that contains several hundred lines of code and a Car class that contains only a few dozen lines of code. Now suppose you want to make an AquaticCar class. Rank the following approaches so that the best approach comes first.
a. Make AquaticCar inherit from both Boat and Car.
b. Make AquaticCar inherit from Boat and implement an ICar interface.
c. Make AquaticCar inherit from Car and implement an IBoat interface.
d. Make AquaticCar implement ICar and IBoat interfaces.
b. Make AquaticCar inherit from Boat and implement an ICar interface.
c. Make AquaticCar inherit from Car and implement an IBoat interface.
d. Make AquaticCar implement ICar and IBoat interfaces.
E6. Suppose you’re building a network application. The Node and Link classes represent a network’s nodes and connecting links. Assuming both of those classes use managed resources, which of the following tasks should the classes do to manage those resources?
a. Implement IDisposable.
b. Provide a Dispose method.
c. Provide a destructor.
d. Implement a Finalize method.
a. Implement IDisposable.
b. Provide a Dispose method.
E7. Suppose the Polygon class uses managed resources. Which of the following tasks should the class do to manage its resources?
a. Implement IDisposable.
b. Provide a Dispose method.
c. Provide a destructor.
d. Implement a Finalize method.
a. Implement IDisposable.
b. Provide a Dispose method.
E8. Suppose the PriceData class uses unmanaged resources. Which of the following tasks should the class do to manage its resources?
a. Implement IDisposable.
b. Provide a Dispose method.
c. Provide a destructor.
d. Implement a Finalize method.
a. Implement IDisposable.
b. Provide a Dispose method.
c. Provide a destructor.
E9. After freeing resources, which of the following should the Dispose method do?
a. Call GC.Finalize.
b. Call GC.SuppressFinalize.
c. Set GC.Finalize = false.
d. Call the object’s destructor.
b. Call GC.SuppressFinalize.
E10. Under which of the following circumstances should a program not call an object’s Dispose method?
a. The object was initialized in a using statement.
b. The object has no Dispose method.
c. The object implements IDisposable.
d. The program invoked the object’s destructor.
a. The object was initialized in a using statement.
b. The object has no Dispose method.