Overloading: It is a process of using
several procedures with the same name but having different signatures. The
signature changes in number of parameters, type of parameter, and order of
parameter.
Program
Public Class Form1
Private Sub
Button1_Click(ByVal sender
As System.Object, ByVal
e As System.EventArgs)
Handles Button1.Click
raj()
raj(2)
raj(3, 3)
raj("ravi", 1)
raj(100, "rahul")
End Sub
Public
Overloads Sub raj()
MsgBox("Hello Raj")
End Sub
Public
Overloads Sub raj(ByVal
x As Integer)
MsgBox(x * 5)
End Sub
Public
Overloads Sub raj(ByVal
x As Integer,
ByVal y As Integer)
MsgBox(x + y)
End Sub
Public
Overloads Sub raj(ByVal
s As String,
ByVal x As Integer)
MsgBox(s & ":has achieved rank" & x)
End Sub
Public
Overloads Sub raj(ByVal
x As Integer,
ByVal s As String)
MsgBox(s & ":has secured" & x)
End Sub
End Class
Overriding: - It is the characteristics of the
child or derived class, which overrides the characteristics of the parent class.
The procedure in the base class, which could be overrides, is prefixed with the
keyword
Overridable. The
procedure in the child class, which
Overrides the base class
procedure, is prefixed with the keyword overrides.
Mybase
keyword is used in the child class to call the parent class procedure.
Program
Public Class Form2
Dim a As New sagar1
Dim b As New sagar2
Private Sub
Button1_Click(ByVal sender
As System.Object, ByVal
e As System.EventArgs)
Handles Button1.Click
MsgBox(a.amit(10, 20))
MsgBox(b.amit(10, 20))
End Sub
Public Class
sagar1
Public
Overridable Function amit(ByVal
x As Integer,
ByVal y As Integer)
Dim z As Integer
z = x + y
Return z
End Function
End Class
Public Class
sagar2
Inherits sagar1
Public
Overrides Function amit(ByVal
x As Integer,
ByVal y As Integer)
Dim z As Integer
z = MyBase.amit(x, y) * 5
Return z
End Function
End Class
End Class
Thanks for
reading.