February 2019
Intermediate to advanced
626 pages
15h 51m
English
Classes in PowerShell can inherit from other classes (both classes in PowerShell and classes from the .NET Framework). The properties, constructors, and methods in a base class are available to an inheriting class.
The following example defines two classes – the second inherits from the first:
class MyBaseClass { [String]$BaseProperty = 'baseValue'}class MyClass : MyBaseClass { [String]$Property = 'Value'}
The BaseProperty property is made available on instances of the child class:
PS> [MyClass]::new()Property BaseProperty-------- ------------Value baseValue
Members may be overridden by re-declaring the member on the inheriting class. The ToString method implementation from the base class is overridden in the following example: ...
Read now
Unlock full access