O'Reilly logo

Learning C# 3.0 by Brian MacDonald, Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 6: Object-Oriented Programming

Quiz Solutions

Solution to Question 6-1. New (user-defined) types are most often created in C# with the keyword class.

Solution to Question 6-2. A class defines a new type; an object is an instance of that type.

Solution to Question 6-3. Making your member fields private allows you to change how you store that data (as a member variable, or in a database) without breaking your client’s code.

Solution to Question 6-4. Encapsulation is the principle of keeping each class discrete and self-contained, so you can change the implementation of one class without affecting any other class.

Solution to Question 6-5. Specialization allows a new class to “inherit” many of the characteristics of an existing class, and to be used polymorphically with that class. Specialization is implemented in C# through inheritance.

Solution to Question 6-6. Polymorphism is the ability to treat derived classes as though they were all instances of their base class, yet have each derived class specialize its own implementation of the base class’s methods.

Solution to Question 6-7. The is-a relationship is established through inheritance. The has-a relationship is implemented through aggregation (making one type a member variable of another type).

Solution to Question 6-8. Access modifiers indicate which class’s methods have access to a given field, property, or method of a class. Public members are available to methods of any class; private members are available only to methods ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required