Inheritance with VB.NET 2005 - Adding your own members to the sub class during inheritance
(Page 3 of 6 )
In the previous section, we examined a very simple and basic inheritance. In this section, I shall extend the class "Second" further as follows:
Public Class Second
Inherits First
Private m_z As Integer
Public Property Z() As Integer
Get
Return m_z
End Get
Set(ByVal value As Integer)
m_z = value
End Set
End Property
Public Function getSum() As Integer
Dim s As Integer
s = Me.X + Me.Y + Me.Z
Return s
End Function
End Class
If you observe carefully, the above class contains all the following members:
- M_x (virtual and not accessible)
- M_y (virtual and not accessible)
- M_z (visual and accessible)
- X (virtual and accessible)
- Y (virtual and accessible)
- Z (visual and accessible)
- getSum (visual and accessible)
To work with the above class, I can code the button click as follows:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim obj As New Second
With obj
.X = 10
.Y = 20
.Z = 30
Me.Label1.Text = .getSum
End With
End Sub
Next: Multi-level inheritance in Visual Basic 2005 >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee