2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Powershellでクラスの継承のプログラムを実装しました。

# Powershell class Test4
# 新規作成 2023/3/15

class TestClass4{
    [int] $ID
    [String] $Name
    
    
    #コンストラクタ
    Disp([int] $ID,[String] $Name) {
        $this.Id = $Id
        $this.Name = $Name
    
    }
    #ToStringメソッド
    [String] ToString() {
        return "Id=" + $this.Id + ",Name=" + $this.Name
    }
    #ToNameメソッド
    [String] ToName() {
        return "私の名前は" + $this.Name + "です。"
    }
    


}

# TestClass4を継承して、testClass5を作成する。
class TestClass5 : TestClass4{
    [String] Livein(){
        $Data = ([Testclass4]$this).ToName()
        $Data += "出身は立川市です"
        return $Data
    }
}

$T1 = New-Object TestClass4
$T1.Disp(1,"白石麻衣")
$T1.ToString()
$T1.ToName()

$T2 = New-Object TestClass5
$T2.Disp(2,"山下美月")
$T2.ToString()
$T2.ToName()
$T2.Livein()
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?