Overriding in vb.net

Satyapriyanayak
Posted by Satyapriyanayak under VB.NET category on | Points: 40 | Views : 764
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

Comments or Responses

Login to post response