Nested Class Demo : Class Define « Class « VB.Net






Nested Class Demo

Nested Class Demo
Imports System

Public Class MainClass
    
    Shared Sub Main()
         Dim f1 As New Fraction(3, 4)
         Console.WriteLine("f1: {0}", f1.ToString(  ))

         Dim fa As New Fraction.FractionArtist(  )
         fa.Draw(f1)
    End Sub
End Class


 Public Class Fraction
     Private numerator As Integer
     Private denominator As Integer

     Public Sub New( _
       ByVal numerator As Integer, ByVal denominator As Integer)
         Me.numerator = numerator
         Me.denominator = denominator
     End Sub 'New

     Public Overrides Function ToString(  ) As String
         Return [String].Format("{0}/{1}", numerator, denominator)
     End Function 'ToString

     ' Nested Class
     Class FractionArtist
         Public Sub Draw(ByVal f As Fraction)
             Console.WriteLine("Drawing the numerator: {0}", f.numerator)
             Console.WriteLine( _
                 "Drawing the denominator: {0}", f.denominator)
         End Sub 'Draw
     End Class 'FractionArtist

 End Class 'Fraction


           
       








Related examples in the same category

1.Your Complex Number ClassYour Complex Number Class
2.Class CompositionClass Composition
3.Define and use your own Time ClassDefine and use your own Time Class