Ancestor Constructor's

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alex

    #1

    Ancestor Constructor's

    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?



  • Herfried K. Wagner [MVP]

    #2
    Re: Ancestor Constructor's

    "Alex" <pleazze@no.mai l> schrieb:[color=blue]
    > 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?[/color]

    No.

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://classicvb.org/petition/>

    Comment

    • Robin Tucker

      #3
      Re: Ancestor Constructor's

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

      "Alex" <pleazze@no.mai l> wrote in message
      news:uEQGcQUXFH A.3488@tk2msftn gp13.phx.gbl...[color=blue]
      > 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?
      >
      >
      >[/color]


      Comment

      • Alex

        #4
        Re: Ancestor Constructor's

        "Robin Tucker" <idontwanttobes pammedanymore@r eallyidont.com> wrote in message
        news:d6kr8k$fkt $1$8300dec7@new s.demon.co.uk.. .[color=blue]
        > It seems to me, that if you need to do this something is wrong with your
        > class structure. Example?[/color]

        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.


        Comment

        • Alex

          #5
          Re: Ancestor Constructor's

          Thanks.


          Comment

          Working...