Class with two constructors : Constructor « Class « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Date Time
8.Development
9.Event
10.File Directory
11.Generics
12.GUI
13.Internationalization I18N
14.Language Basics
15.LINQ
16.Network Remote
17.Reflection
18.Security
19.Thread
20.Windows Presentation Foundation
21.Windows System
22.XML
23.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Class » ConstructorScreenshots 
Class with two constructors
Class with two constructors

Imports System

Public Class MainClass
    
    Shared Sub Main()
       Dim currentTime As DateTime = DateTime.Now
       Dim time1 As New Time(currentTime)
       time1.DisplayCurrentTime(  )

       Dim theHour As Integer = time1.Hour

       Console.WriteLine("Retrieved the hour: {0}", _
        theHour)

       theHour += 1

       time1.Hour = theHour

       Console.WriteLine("Updated the hour: {0}", _
        time1.Hour)

    End Sub
End Class

 Public Class Time

    Private mYear As Integer
    Private mMonth As Integer
    Private mDayOfMonth As Integer
    Private mHour As Integer
    Private mMinute As Integer
    Private mSecond As Integer

    Property Hour(  ) As Integer
       Get
          Return mHour
       End Get
       Set(ByVal Value As Integer)
          mHour = Value
       End Set
    End Property


    ' public accessor methods
    Public Sub DisplayCurrentTime(  )
       Console.WriteLine_
       "{0}/{1}/{2} {3}:{4}:{5}", _
       mMonth, mDayOfMonth, mYear, Hour, mMinute, mSecond)
    End Sub 'DisplayCurrentTime


    ' constructors
    Public Sub New(ByVal dt As DateTime)
       mYear = dt.Year
       mMonth = dt.Month
       mDayOfMonth = dt.Day
       mHour = dt.Hour
       mMinute = dt.Minute
       mSecond = dt.Second
    End Sub 'New


    Public Sub New_
    ByVal mYear As Integer, _
    ByVal mMonth As Integer, _
    ByVal mDayOfMonth As Integer, _
    ByVal mHour As Integer, _
    ByVal mMinute As Integer, _
    ByVal mSecond As Integer)
       Me.mYear = mYear
       Me.mMonth = mMonth
       Me.mDayOfMonth = mDayOfMonth
       Me.Hour = mHour
       Me.mMinute = mMinute
       Me.mSecond = mSecond
    End Sub 'New

 End Class 'Time

           
       
Related examples in the same category
1.Call base constructorCall base constructor
2.Constructor with parametersConstructor with parameters
3.Use Constructor to init member variables
4.Multiplie Constructors
5.Init Member Variables through ConstructorInit Member Variables through Constructor
6.Overload Constructor DemoOverload Constructor Demo
7.Overloading constructorsOverloading constructors
ww___w___.__ja_va_2s__.c_o___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.