I just work through a book about OOP (Object-Oriented Programming with visual Basic .NET by J.P.Hamilton). At a point where he has explained overloading but not yet override he writes: "You can only overload methods in a class; this is, you can add new methods that have the same name as existing methods. However, existing behavior cannot be redefined."
But as far as I understand you can redefine a method from a child class using overload like:
Public Class clsTest
Sub addition(ByVal x As Integer)
MsgBox(x)
End Sub
End Class
Public Class clsTest2 : Inherits clsTest
Overloads Sub addition(ByVal x As Integer)
MsgBox(x * x)
End Sub
End Class
If this is correct, then I would like to know, when to use overload and when to use override to redifine a method, since
Public Class clsTest
Overridable Sub addition(ByVal x As Integer)
MsgBox(x)
End Sub
End Class
Public Class clsTest2 : Inherits clsTest
Overrides Sub addition(ByVal x As Integer)
MsgBox(x * x)
End Sub
End Class
gives me the same output.