首页 > 代码库 > 面向对象特性之多态

面向对象特性之多态

废话少说,直接上代码:

技术分享

 

‘可飞行的
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

 

面向对象特性之多态