ネタ元→東方算程譚:オブジェクト指向におけるFizzBuzz問題
別にかわったことないんですけど参加することに意義があるんでした・・・っけ?w
Module Program
Sub Main()
Dim a As Animal
a = New Dog
a.Sound()
a.SetCount(3)
a.Sound()
a = New Cat
a.Sound()
End Sub
End Module
Public MustInherit Class Animal
Protected _count As Integer = 1
Public MustOverride Sub Sound()
Public Sub SetCount(ByVal count As Integer)
Me._count = count
End Sub
End Class
Imports System.Text
Public Class Cat
Inherits Animal
Public Overrides Sub Sound()
Dim sb As New StringBuilder
For i As Integer = 1 To Me._count
sb.Append("ニャー")
Next
Console.WriteLine(sb.ToString)
End Sub
End Class
Public Class Dog
Inherits Animal
Public Overrides Sub Sound()
For i As Integer = 1 To Me._count
Console.Write("わん")
Next
Console.WriteLine()
End Sub
End Class