Ancestor Constructor's

  • Thread starter Thread starter Alex
  • Start date Start date
A

Alex

The following statement appears in the Help under the heading Using
Constructors And Destructors:

"When you define a class derived from another class, the first line of a
constructor must be a call to the constructor of the base class, unless the
base class has an accessible constructor that takes no parameters. A call to
the base class containing the above constructor, for example, would be
MyBase.New(s). Otherwise, MyBase.New is optional, and the Visual Basic .NET
runtime calls it implicitly."

Based on that statement, my understanding is that when a class gets created,
the first thing that happens is that the classes' ancestor constructor gets
executed. Is it possible to have code in the derived class constructor that
executes before the code in the ancestor class does?
 
It seems to me, that if you need to do this something is wrong with your
class structure. Example?
 
Alex said:
Based on that statement, my understanding is that when a class gets
created,
the first thing that happens is that the classes' ancestor constructor
gets
executed. Is it possible to have code in the derived class constructor
that
executes before the code in the ancestor class does?

No.
 
Robin Tucker said:
It seems to me, that if you need to do this something is wrong with your
class structure. Example?

I grant you that it doesn't make for a clean design, but when inheriting one
doesn't always have control over what happens in the ancestor classes. An
example would be if you want to save state before the code in the ancestor's
constructor gets executed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top