Class Composition : Class Define « 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 » Class DefineScreenshots 
Class Composition
Class Composition

Imports System

Public Class MainClass

    Shared Sub Main(ByVal args As String())
      Dim As New CStudent_
         "A""B"72419493121988)

      Console.WriteLine(s.ToStandardString() )
      
    End Sub
End Class

' Encapsulates month, day and year.
Class CDay
   Inherits Object

   Private mMonth As Integer ' 1-12
   Private mDay As Integer ' 1-31 based on month
   Private mYear As Integer ' any year

   Public Sub New(ByVal monthValue As Integer, _
      ByVal dayValue As Integer, ByVal yearValue As Integer)

      mMonth = monthValue
      mYear = yearValue
      mDay = dayValue

   End Sub ' New

   ' create string containing month/day/year format
   Public Function ToStandardString() As String
      Return mMonth & "/" & mDay & "/" & mYear
   End Function

End Class 


' Represent student name, birthday and hire date.

Class CStudent
   Inherits Object

   Private mFirstName As String
   Private mLastName As String
   Private mBirthDate As CDay ' member object reference
   Private mHireDate As CDay ' member object reference

   ' CStudent constructor
   Public Sub New(ByVal firstNameValue As String, _
      ByVal lastNameValue As String, _
      ByVal birthMonthValue As Integer, _
      ByVal birthDayValue As Integer, _
      ByVal birthYearValue As Integer, _
      ByVal hireMonthValue As Integer, _
      ByVal hireDayValue As Integer, _
      ByVal hireYearValue As Integer)

      mFirstName = firstNameValue
      mLastName = lastNameValue

      ' create CDay instance for employee birthday
      mBirthDate = New CDay(birthMonthValue, birthDayValue, _
         birthYearValue)

      ' create CDay instance for employee hire date
      mHireDate = New CDay(hireMonthValue, hireDayValue, _
         hireYearValue)
   End Sub ' New

   ' return employee information as standard-format String
   Public Function ToStandardString() As String
      Return mLastName & ", " & mFirstName & " Hired: " _
         & mHireDate.ToStandardString() " Birthday: " & _
         mBirthDate.ToStandardString()
   End Function ' ToStandardString

End Class ' CStudent

           
       
Related examples in the same category
1.Nested Class DemoNested Class Demo
2.Your Complex Number ClassYour Complex Number Class
3.Define and use your own Time ClassDefine and use your own Time Class
ww_w__._j___a__va__2__s_.___co__m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.