Multilevel inheritance : Class Inheritance « Class Module « VB.Net Tutorial






Class Person
    Public Name As String
    Public Age As Integer

    Public Sub New(ByVal Name As String, ByVal Age As Integer)
        Me.Name = Name
        Me.Age = Age
    End Sub
End Class

Class Player
    Inherits Person

    Public Sport As String
    Public Team As String

    Public Sub New(ByVal Name As String, ByVal Age As Integer, _
    ByVal Sport As String, ByVal Team As String)
        MyBase.New(Name, Age)
        Me.Team = Team
        Me.Sport = Sport
    End Sub
End Class

Class BasketPlayer
    Inherits Player

    Public PointsPerGame As Double
    Public Rebounds As Double

    Public Sub New(ByVal Name As String, ByVal Age As Integer, _
    ByVal Sport As String, ByVal Team As String, ByVal Points As Double, ByVal Rebounds As Double)

        MyBase.New(Name, Age, Sport, Team)
        Me.PointsPerGame = Points
        Me.Rebounds = Rebounds
    End Sub

    Public Sub Show()
        Console.WriteLine("Player: " & Name)
        Console.WriteLine("Age: " & Age)
        Console.WriteLine("Sport: " & Sport)
        Console.WriteLine("Team: " & Team)
        Console.WriteLine("Points: " & PointsPerGame)
        Console.WriteLine("Rebounds: " & Rebounds)
    End Sub
End Class

Module Module1
    Sub Main()
        Dim K As New BasketPlayer("AA", 12, "Basketball", "Team", 25.5, 6.3)
        K.Show()
    End Sub

End Module
Player: AA
Age: 12
Sport: Basketball
Team: Team
Points: 25.5
Rebounds: 6.3








6.14.Class Inheritance
6.14.1.Simple Inheritance
6.14.2.Class implicitly Inherits Object
6.14.3.Circle class that inherits from class Point
6.14.4.Inherit ToString method from Object
6.14.5.Call base method
6.14.6.Shadows member function from base class
6.14.7.Use For Each for Class Hierarchy
6.14.8.Inherit constant from base class
6.14.9.Class inheritance and polymorphism
6.14.10.Multilevel inheritance