Constructors and Destructors

Constructors and destructors in a base class are not inherited in the derived class. A derived class has a base portion and a derived portion. The base constructor initializes the base portion, and the constructor of the derived class initializes the derived portion. For the derived object, the default constructor of the base class is called by default to initialize the state of the base class. If the base class does not have a default constructor, a compiler error occurs unless the derived class calls a constructor in the base class that has parameters. In the following code, ZClass does not have a default constructor. A compiler error will occur:

public class ZClass { public ZClass(int param) { } } public class YClass ...

Get Programming Microsoft® Visual C#® 2008: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.