Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

9: Defining Classes > Exercises

Exercises

  1. What is wrong with the following code?
    public sealed class MyClass
    {
          // Class members.
    }
    
    public class myDerivedClass : MyClass
    {
          // Class members.
    }
  2. How would you define a noncreatable class?
  3. Why are noncreatable classes still useful? How do you make use of their capabilities?
  4. Write code in a class library project called Vehicles that implements the Vehicle family of objects discussed earlier in this chapter, in the section on interfaces versus abstract classes. There are nine objects and two interfaces that require implementation.
  5. Create a console application project, Traffic, which references Vehicles.dll (created in question 4). Include a function called AddPassenger() that accepts any object with the IPassengerCarrier interface. To prove that the code works, call this function using instances of each object that supports the interface, calling the ToString() method inherited from System.Object on each one and writing the result to the screen.

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint