Module Module1
Class Person 'base class
Private strName As String 'strName as a private member
Public intAge As Integer 'intAge as a public member
Public Function getName()
Return strName
End Function
Public Function getAge()
Return intAge
End Function
Public Sub setName(ByVal name As String)
strName = name
End Sub
Public Overridable Sub Play()
System.Console.WriteLine("I Play Nothing")
End Sub
End Class
Class CricketPlayer 'derived class
Inherits Person 'the keyword "Inherits" is used to inherit from a class
Public strNationality As String 'derived classes member
Function getNationality()
Return strNationality
End Function
Public Overrides Sub Play()
System.Console.WriteLine("I can Play Cricket")
End Sub
End Class
Sub Main()
System.Console.WriteLine("Polymorphism Example")
Dim Player As New CricketPlayer
System.Console.WriteLine()
Player.Play()
Dim Person1 As New Person
System.Console.WriteLine()
Person1.Play()
Dim CricPlayer As New CricketPlayer
Dim person2 As Person
person2 = CricPlayer
System.Console.WriteLine()
person2.Play()
System.Console.WriteLine()
End Sub
End Module