Class Composition : Class Define « Class « VB.Net

VB.Net
1. 2D
2. Application
3. Class
4. Data Structure
5. Database ADO.net
6. Development
7. Event
8. File Directory
9. Generics
10. GUI
11. Language Basics
12. Network Remote
13. Thread
14. Windows System
15. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net Tutorial
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
w__w__w.__j__ava_2__s___.___co_m_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.