Question Class Inheritance

DekaFlash

Well-known member
Joined
Feb 14, 2006
Messages
117
Programming Experience
1-3
I have the following class definition

VB.NET:
Public Class Car
    Public ReadOnly MaxSpeed As Integer
    Private CurrSpeed As Integer

    Public Sub New()

    End Sub
    Public Sub New(ByVal max As Integer)
        MaxSpeed = 55
    End Sub

    Public Property Speed() As Integer
        Get
            Return CurrSpeed
        End Get
        Set(ByVal value As Integer)
            CurrSpeed += value
            If CurrSpeed > MaxSpeed Then
                CurrSpeed = MaxSpeed
            End If
        End Set
    End Property
End Class

Public Class MiniVan
    Inherits Car

End Class

In the main code I access it as follows

VB.NET:
Module Module1

    Sub Main()
        Dim myCar As New Car(80)
        myCar.Speed = 50
        Console.WriteLine("My car is going {0} MPH", myCar.Speed)
        Console.WriteLine()

        Dim myVan As New MiniVan()
        myVan.Speed = 10
        Console.WriteLine("My van is going {0} MPH", myVan.Speed)
        Console.WriteLine()
        Console.ReadLine()
    End Sub

End Module

When I run the Console App, I get the following output but I believe I should be getting - My van is going 10 mph.

My car is going 50 MPH

My van is going 0 MPH

Can somebody please explain, where I am going wrong?

Thanks
 
Top Bottom