DotNet · 2022年2月26日

Overloads的特性

父类Overloads了祖类的方法,子类没有重新定义,则默认调用时,会调用父类中Overload的方法,如下图所示:

 Sub Main()
        Dim s As New S3()
        s.Method()
        CType(s, S2).Method()
        CType(s, S1).Method()
        Console.ReadLine()
    End Sub


End Module

Class S1
    Public Sub Method()
        Console.WriteLine("这是S1实例方法")
    End Sub
End Class
Class S2
    Inherits S1
    Public Overloads Sub Method()
        Console.WriteLine("这是S2实例方法")
    End Sub
End Class
Class S3
    Inherits S2
    'Public Overloads Sub Method()
    '    Console.WriteLine("这是S3实例方法")
    'End Sub
End Class

输出效果:

最新电影,电视剧,尽在午夜剧场

电影电视剧午夜不寂寞