.Net Programming

Inheritance in VB.Net

Implementating Inheritance by inheriting A Base class to create a derived class in VB.Net

Language : VB.Net
[sourcecode language='vb']
Public MustInherit Class emp
Public empNo As Integer
Public empSalary As Integer
Public empDept As String
Public empName As String

Sub getData()
empName = txtName.Text
empDept = txtDept.Text
empSalary = Val(txtSalary.Text)
empNo = Val(txtNo.Text)

End Sub
Overridable Function calSal(ByVal sal As Integer)
Return empSalary
End Function
Sub dispData()
MsgBox(“Salary of ” & txtName.Text & ” is : ” & empSalary)
empSalary = 0
End Sub

Private Sub cmdSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click
getData()
If (ComType.SelectedItem.Equals(“Temporary”)) Then
Dim temp = New temporary()
empSalary = temp.calSal(empSalary)
Else
Dim perm = New permanent()
empSalary = perm.calSal(empSalary)
End If
dispData()
End Sub
End Class

Public Class temporary
Inherits emp
Overrides Function calSal(ByVal sal As Integer)
sal = sal + 4000
Return sal
End Function
End Class
Public Class permanent
Inherits emp
Overrides Function calSal(ByVal sal As Integer)
sal = sal + 8000
Return sal
End Function
End Class
[/sourcecode]



Leave a Comment

Notify me of followup comments via e-mail. You can also subscribe without commenting.


WordPress - Vaibhav Kanwal