What about that “Private Sub MessageUser()” line from our previous example? It’s a private sub, as the name states, but try to access it from outside the Vehicle class. In the MainForm_Load() sub, try adding Van.MessageUser. You should get a build error that states ‘Vehicle.Private Sub MessageUser()’ is not accessible in this context because it [...]
Archive for the ‘OOP’ Category
A Note on Variable Scope
Posted in OOP on October 7, 2009 | Leave a Comment »
Classes vs. Objects
Posted in OOP on October 7, 2009 | Leave a Comment »
I know I said this was object-oriented programming. So why am I talking about classes? The answer to this question is that all objects are classes. (Mind-blowing, huh?) The way to separate the difference between objects and classes is quite easy. An object has an IS-A relationship, while a class has a HAS-A relationship.
A car [...]
Get() and Set() Class Property
Posted in OOP on October 6, 2009 | Leave a Comment »
Public Class Hello
Private _sample As String
Public Property Sample() As String
Get
‘1
Return _sample
End Get
Set(ByVal Value As String)
‘2
_sample = Value
End Set
End Property
Public Sub DoSomething()
Me.Sample = “SampleText” ‘2
MessageBox.Show(Me.Sample) ‘1
End Sub
End Class