Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 6 - Polymorphism using Abstract Classes in Vis...
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
eWeek
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Polymorphism using Abstract Classes in Visual Basic.NET 2005
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 14
    2007-08-01

    Table of Contents:
  • Polymorphism using Abstract Classes in Visual Basic.NET 2005
  • Life without the Abstract class in Visual Basic 2005: continued
  • Defining and implementing abstract classes in Visual Basic 2005: abstract class
  • Defining and implementing abstract classes in Visual Basic 2005: child class
  • Defining and implementing abstract classes in Visual Basic 2005: child classes continued
  • Making use of Polymorphism using abstract classes in Visual Basic 2005

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Polymorphism using Abstract Classes in Visual Basic.NET 2005 - Making use of Polymorphism using abstract classes in Visual Basic 2005
    (Page 6 of 6 )

    Since you are now familiar with abstract methods and abstract classes, it is time to learn about polymorphism.

    Let us modify the code for testing as follows:

        Dim sh As Shape

        sh = New Rectangle(10, 20)

        MessageBox.Show("Area of rectangle: " & sh.GetArea)

        sh = New Square(20)

        MessageBox.Show("Area of square: " & sh.GetArea)

        sh = New EquiTriangle(5, 10)

        MessageBox.Show("Area of triangle: " & sh.GetArea)

    In the above code, I am always using the same variable (reference variable, and it is not a concrete object) to hold the instances of all child classes -- "Rectangle," "Square" and "EquiTriangle." 

    You can also observe that I am using the same variable "sh" and calling the same method "GetArea" with different results. Using the same method with different implementations and different executions at run-time is nothing but polymorphism.

    A final note! We can never create any concrete object (an instance with a "new" operator) or instantiate on any abstract class. For example, the following declaration is invalid:

    Dim shp As New Shape(10, 20)

    This is because any abstract class is never completely implemented (it contains abstract methods without any implementation). If there exists no implementation for a method, we will not be able to access it using an object (or instance).  And hence, we will not be able to instantiate any abstract class.

    I hope you enjoyed the article and any suggestions, bugs, errors, enhancements etc. are highly appreciated at http://jagchat.spaces.live.com


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hai,This is my new article (adding to the series of object oriented programming...
       · I like the way the author explains the concept with simple examples.I would like to...
     

    VISUAL BASIC.NET ARTICLES

    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...
    - Shadowing using Shadows in Visual Basic.NET ...
    - Overloading and Overriding in Visual Basic.N...
    - More on Controlling Windows Fax Services Usi...
    - Programmatically Controlling Windows Fax Ser...
    - Focusing on Forms and Menus in Visual Basic
    - Manipulating Forms with the Windows Forms Li...
    - Basics of the Windows Forms Library
    - Forms, Controls, and Other Useful Objects
    - Implementing OOP to Develop Database Oriente...
    - Using Themes and Skins for Personalization w...
    - A Deeper Look at Personalization using Visua...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway