Re: Sub class constructor

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: MN (1[n.m-recrut1]at2[ifrance2]dot3[com3])
Date: 12/23/04


Date: Thu, 23 Dec 2004 10:00:25 +0100

If you want to use parent constructors when instanciating your child class,
you need to implement the 3 constructors in your child class and call parent
constructor from it;

public class Parent
  public sub New()
    MyBase.New
    ...
  end sub

  public sub New(i as integer)
     MyBase.New(i)
     ...
  end sub

  public sub New(i as integer, s as string)
     MyBase.New(i, s)
     ...
  end sub

  ...
 end class

Note that when you instantiate a class, you are calling the class
constructors not parent class constructor;

Regards.

"JC Voon" <jcvoon_99@yahoo.com> a écrit dans le message de news:
41ca75fa.25514988@msnews.microsoft.com...
> Hi:
>
> The parent class have 3 version of constructor:
>
> public class Parent
> public sub New()
> end sub
>
> public sub New(i as integer)
> myclass.New()
> ...
> end sub
>
> public sub New(i as integer, s as string)
> myclass.New()
> ...
> end sub
> end class
>
>
> public class Child
> inherits Parent
>
> end class
>
>
> When i try to create the Child object, i can only use the New() as a
> constructor, the others 2 constructor is not accessable, what am i
> missing ?
>
> Thanks
> JCVoon
>
>
>
>
>
>



Relevant Pages

  • Re: What does the CLR do when you instantiate an object? - Continue
    ... > cast an object to one of its parent types then yes I'd agree with you. ... >child class in the memory, when I asked you whether you are confident to ... in the PARENT CONSTRUCTOR we have shown working examples ...
    (microsoft.public.dotnet.framework.clr)
  • Re: What does the CLR do when you instantiate an object? - Continue
    ... process right at the beginning of the ChildClass constructor. ... built before the parent constructor is called. ... exists and it is created before the object of the child class instantiation ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Using a Resource as a Class Property
    ... automatically call the parent constructor, ... class constructor automatically before any code is executed in the child class constructor. ... PHP doesn't automatically call constructors BUT doing so would be more in keeping with the Tao of OOP. ... I seriously considered writing the classes in a way to where the parent would *presume* all kinds of stuff about the child, but it didn't jibe with my obsession with atomicity - so I didn't do it. ...
    (comp.lang.php)
  • Re: Using a Resource as a Class Property
    ... But as soon as your child class uses its own ... constructor, you have to manually call the parent one. ... Is that a normal OOP way to do it - done that way in C++ and whatnot - or is this unique to PHP? ...
    (comp.lang.php)
  • Sub class constructor
    ... The parent class have 3 version of constructor: ... public sub New ...
    (microsoft.public.dotnet.languages.vb)