Instance constructors, on the other hand, are called when an instance of a class is created.
They typically set up the state of the object by initializing the fields to a desired predefined
state. You can also do any other type of initialization work, such as connecting to a database
and opening a file. A class can have multiple instance constructors that can be overloaded.
Instance constructors can execute parent and self-constructors via MyBase.New() and
Me.New(), as in the following snippets:
Public Sub New()
MyBase.New()
End Sub
CHAPTER 3 n CLASSES AND STRUCTURES 36
Public Sub New(ByVal aString as String)
Me.New()
End Sub
Accessibility
Access modifiers can be used on just about any defined entity in a VB program, including
classes and any member within the class. Access modifiers applied to a class affect its visibility
from inside and outside the containing assembly. Access modifiers applied to class members,
including methods, fields, properties, and events affect the visibility of the member from outside
of the class. Table 3-1 describes the various access modifiers available.
Table 3-1. Access Modifiers in VB
Access Modifier Meaning
Public Member is completely visible outside both the defining scope and the
internal scope.
Pages:
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90