Protected Members : Protected « Class Module « VB.Net Tutorial

VB.Net Tutorial
1. Language Basics
2. Data Type
3. Operator
4. Statements
5. Date Time
6. Class Module
7. Development
8. Collections
9. Generics
10. Attributes
11. Event
12. Stream File
13. GUI
14. GUI Applications
15. 2D Graphics
16. I18N Internationlization
17. Reflection
18. Regular Expressions
19. Security
20. Socket Network
21. Thread
22. Windows
23. XML
24. Database ADO.net
25. Design Patterns
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
VB.Net Tutorial » Class Module » Protected 
6. 24. 3. Protected Members
 
 

Module Tester

   Sub Main()
      Dim circle As Circle

      circle = New Circle(37432.5' instantiate Circle

      Console.WriteLine("X coordinate is " & circle.X & vbCrLf & _
         "Y coordinate is " & circle.Y & vbCrLf & "Radius is " & _
         circle.Radius)

      circle.X = 2
      circle.Y = 2
      circle.Radius = 4.25

      Console.WriteLine("The new location and radius of circle are " & _
         vbCrLf & circle.ToString())

      Console.WriteLine("Diameter is " & _
         String.Format("{0:F}", circle.Diameter()))

      Console.WriteLine("Circumference is " & _
         String.Format("{0:F}", circle.Circumference()))

      Console.WriteLine("Area is " & String.Format("{0:F}", circle.Area()))

   End Sub ' Main

End Module 


Public Class Point
   Protected mX, mY As Integer

   Public Sub New()
      X = 0
      Y = 0
   End Sub ' New

   Public Sub New(ByVal xValue As Integer, _
      ByVal yValue As Integer)

      X = xValue
      Y = yValue
   End Sub ' New

   Public Property X() As Integer
      Get
         Return mX
      End Get

      Set(ByVal xValue As Integer)
         mX = xValue ' no need for validation
      End Set

   End Property ' X

   Public Property Y() As Integer
      Get
         Return mY
      End Get

      Set(ByVal yValue As Integer)
         mY = yValue ' no need for validation
      End Set

   End Property ' Y

   Public Overrides Function ToString() As String
      Return "[" & mX & ", " & mY & "]"
   End Function ' ToString

End Class 


Public Class Circle
   Inherits Point ' Circle Inherits from class Point

   Private mRadius As Double ' Circle's radius

   Public Sub New()
      Radius = 0
   End Sub ' New

   Public Sub New(ByVal xValue As Integer, _
      ByVal yValue As Integer, ByVal radiusValue As Double)
      mX = xValue
      mY = yValue
      Radius = radiusValue
   End Sub ' New

   Public Property Radius() As Double
      Get
         Return mRadius
      End Get

      Set(ByVal radiusValue As Double)

         If radiusValue > Then
            mRadius = radiusValue
         End If

      End Set

   End Property ' Radius

   Public Function Diameter() As Double
      Return mRadius * 2
   End Function ' Diameter

   ' calculate Circle circumference
   Public Function Circumference() As Double
      Return Math.PI * Diameter()
   End Function ' Circumference

   ' calculate Circle area
   Public Overridable Function Area() As Double
      Return Math.PI * mRadius ^ 2
   End Function ' Area

   ' return String representation of Circle
   Public Overrides Function ToString() As String
      Return "Center = " "[" & mX & ", " & mY & "]" & _
         "; Radius = " & mRadius
   End Function ' ToString

End Class

        
  
  




X coordinate is 37
Y coordinate is 43
Radius is 2.5
The new location and radius of circle are
Center = [2, 2]; Radius = 4.25
Diameter is 8.50
Circumference is 26.70
Area is 56.75

 
6. 24. Protected
6. 24. 1. protected members are available to objects inheriting from this class
6. 24. 2. protected friend members are available to any object that is in the same assemby or inherits from this class, or both.
6. 24. 3. Protected Members
w__w__w_.___ja_v__a__2_s.c_o___m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.