stu nicholls dot com | menu - Professional dropdown #3

click here


Member Access Modifiers and their effect:

Shared Memebers Example:

Public Shared i As Integer Accessing Shared Memebers Public Class Form1 Public ob1 As New AddNum()
Public ob2 As New AddNum()
Public Class AddNum
Private j As Integer
Public Shared i As Integer = 1
Shared Function Add(ByVal a As Integer, ByVal b As
Integer) As Integer
Dim k As Integer = 66 'can use its member
'j=65 can not use because j is an instance member
MessageBox.Show(i, "From shared Function")
MessageBox.Show(k, "From shared Function")
Return a + b
End Function
Public Sub disp()
j = 55
i = i + 1
MessageBox.Show(i, "From Object")
MessageBox.Show(j, "From Object")
End Sub
End Class
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
TextBox3.Text = AddNum.Add(TextBox1.Text, TextBox2.Text)
MessageBox.Show(AddNum.i, "Direct Access")
ob1.disp()
ob2.disp()
MessageBox.Show(AddNum.i, "Direct Access")
End Sub
End Class

<< Previous

comments powered by Disqus
click here
click here
Footer1