面向对象特性之多态

废话少说,直接上代码:

 

'可飞行的
Public Interface IFlyable

    '开始飞行
    Sub StartFlying()


End Interface

 

Public Class Plane
    Implements IFlyable



    Public Sub StartFlying() Implements IFlyable.StartFlying
        Console.WriteLine("飞机打开引擎飞行")
    End Sub
End Class

 

Public Class Bird
    Implements IFlyable

    Public Sub StartFlying() Implements IFlyable.StartFlying
        Console.WriteLine("鸟儿展开翅膀飞行")
    End Sub

End Class

 

Module Module1

    Sub Main()

        Dim f1 As IFlyable, f2 As IFlyable
        f1 = New Bird()
        f2 = New Plane()

        Flying(f1)
        Flying(f2)

        Console.ReadKey()

    End Sub

    Public Sub Flying(ByVal aircraft As IFlyable)
        aircraft.StartFlying()
    End Sub



End Module

 

posted on 2017-02-04 15:55  墨尔本  阅读(136)  评论(0编辑  收藏  举报

导航