Demonstrate 'is a' relationship : Is « Operator « 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 » Operator » Is 
3. 9. 1. Demonstrate 'is a' relationship
 
 

Class Tester

   
   Shared Sub Main()
      Dim point1, point2 As Point
      Dim circle1, circle2 As Circle

      point1 = New Point(3050)
      circle1 = New Circle(120892.7)

      Console.WriteLine("Point point1: " & point1.ToString() & _
         vbCrLf & "Circle circle1: " & circle1.ToString())

      point2 = circle1

      Console.WriteLine("Circle circle1 (via point2): " & point2.ToString())

      circle2 = CType(point2, Circle' allowed only via cast

      Console.WriteLine("Circle circle1 (via circle2): " & circle2.ToString())

      If (TypeOf point1 Is CircleThen
         circle2 = CType(point1, Circle)
         Console.WriteLine("cast successful")
      Else
         Console.WriteLine("point1 does not refer to a Circle")
      End If
   End Sub

End Class 

Public Class Point
   Private mX, mY As Integer

   Public Sub New()
   End Sub ' New

   Public Sub New(ByVal xValue As Integer, _
      ByVal yValue As Integer)
   End Sub ' New
   Public Overrides Function ToString() As String
      Return "[" & mX & ", " & mY & "]"
   End Function ' ToString

End Class

Public Class Circle
   Inherits Point 

   Private mRadius As Double

   Public Sub New()
   End Sub ' New

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

      MyBase.New(xValue, yValue)
   End Sub ' New

   Public Overrides Function ToString() As String
      Return "Center= " & MyBase.ToString() & _
         "; Radius = " & mRadius
   End Function ' ToString

End Class

        
  
  




Point point1: [0, 0]
Circle circle1: Center= [0, 0]; Radius = 0
Circle circle1 (via point2): Center= [0, 0]; Radius = 0
Circle circle1 (via circle2): Center= [0, 0]; Radius = 0
point1 does not refer to a Circle

 
3. 9. Is
3. 9. 1. Demonstrate 'is a' relationship
3. 9. 2. Use Is and As to convert a class to its implenented Interface
w_w__w_.___j___a__v_a___2_s__.___c__om___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.