O'Reilly logo

Learning C# 2005, 2nd Edition 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 11: Inheritance and Polymorphism

Quiz

Solution to Question 11–1.

This relationship is reciprocal: if you have three types with similar functionality, you can refactor that similarity out of the three types into a generalized type. At the same time, each of the three types are now specialized forms of the more generalized type.

Inheritance is also implicitly hierarchical: you can imagine a tree with the most generalized type at the top and each level of specialization descending from levels above. A generalized type may have many specializations, but each specialized type may have only one generalization.

Solution to Question 11–2.

Through inheritance.

Solution to Question 11–3.

class <identifier> : <base class>

Solution to Question 11–4.

Create a virtual method in the base class, and then override it in the derived class.

Solution to Question 11–5.

The more usual meaning is to allocate memory on the heap. The special meaning in inheritance is that you are not overriding a base method; you are creating a new method that intentionally hides and replaces the base class method.

Solution to Question 11–6.

After the parameter list, but before the opening brace, put a colon followed by the keyword base and two parentheses. Pass the parameters for the base class constructor within the parentheses.

Solution to Question 11–7.

A member of class A is visible to class B if it is marked public, or if it is marked protected and class B derives directly or indirectly from A. If the member is marked

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