I am just working on a book on OOP (Object Oriented Programming with Visual Basic.NET from JPHamilton). The moment he explained the overload, but not yet redefining it, he writes: “You can overload methods only in the class, which means that you can add new methods with the same name as existing methods. However, existing behavior cannot be overridden. "
But as I understand it, you can override a method from a child class using overload, for example:
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 overloading and when to use override to override the 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 result.