Skip to Content
Programming Visual Basic .NET, Second Edition
book

Programming Visual Basic .NET, Second Edition

by Jesse Liberty
April 2003
Intermediate to advanced
560 pages
14h 4m
English
O'Reilly Media, Inc.
Content preview from Programming Visual Basic .NET, Second Edition

Calling the Default Constructor

As mentioned earlier, if you do not create a constructor, an implicit default constructor will be called by the compiler. You can see this at work by commenting out the constructor in Example 7-1:

'Public Sub New( _
'   ByVal xCoordinate As Integer, ByVal yCoordinate As Integer)
'    myXVal = xCoordinate
'    myYVal = yCoordinate
'End Sub 'New

and replacing the first line in Main( ) with one that creates an instance of Location without passing values:

'Dim loc1 As New Location(200, 300)
Dim loc1 As New Location( )

Because there is now no constructor at all, the implicit default constructor is called. The output looks like this:

Loc1 location: 0, 0
Loc2 location: 0, 0

The default constructor has initialized the member variables to zero.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Visual Basic .NET

Programming Visual Basic .NET

Dave Grundgeiger
VB.NET Language in a Nutshell, Second Edition

VB.NET Language in a Nutshell, Second Edition

Steven Roman PhD, Ron Petrusha, Paul Lomax

Publisher Resources

ISBN: 0596004389Supplemental ContentCatalog PageErrata