Class, inheritance, and constructors

I'm learning the syntax for classes in PowerShell 5. One thing I haven't figured out is how to handle inherited classes whose base class has a constructor.

Let's suppose I have the following class:

class computer
{
    [int] $MemorySize
    [int] $DiskSize

    computer([int] $mem, [int] $disk)
    {
        $this.MemorySize = $mem
        $this.DiskSize = $disk
    }
}

Now suppose I want to create a subclass called "laptop" that adds a ScreenSize paramter. How do I write the constructor?

class laptop : computer
{
    [int] $ScreenSize

    laptop(?????

August 26th, 2015 9:19pm

Apparently we cannot use a parameterized constructor in a class if we want it to be inheritable.

Free Windows Admin Tool Kit Click here and download it now
August 27th, 2015 2:55am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics