Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 2 - Shadowing using Shadows in Visual Basic.NE...
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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 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

Shadowing using Shadows in Visual Basic.NET 2005
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 15
    2007-07-31

    Table of Contents:
  • Shadowing using Shadows in Visual Basic.NET 2005
  • Accessing parent members when using Shadows in Visual Basic 2005
  • Using Shadows with properties in Visual Basic 2005
  • Using Shadows with methods in Visual Basic 2005
  • Using Shadows with overloaded parent methods in Visual Basic 2005
  • Using Overloads instead of Shadows with overloaded parent methods 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
     
     
    ADVERTISEMENT


    Shadowing using Shadows in Visual Basic.NET 2005 - Accessing parent members when using Shadows in Visual Basic 2005


    (Page 2 of 6 )

    Let us consider two classes as follows:

    Public Class Parent

      Public x As Integer = 10

    End Class

     

    Public Class Child

      Inherits Parent

      Public Shadows x As Integer = 20 'default is shadows even if it is not defined

    End Class

    To test the above classes, I created two objects and accessed the fields as follows:

        Dim objParent As New Parent

        Dim objChild As New Child

        MessageBox.Show("From Parent: " & objParent.x)

        MessageBox.Show("From Child: " & objChild.x)

    From the above, the first message gives "10" and the second gives "20." 

    Let us consider that I would like to access the parent member from the child object. It can be done using the following style of code:

        Dim objChild As New Child

        Dim RefParent As Parent = objChild

        MessageBox.Show("From child with Parent Ref: " & RefParent.x)

    In the above code "objChild" is a full-fledged instance and "RefParent" is simply a reference to another memory location (no new memory gets allocated for this).  When inheritance is implemented, a child instance can be assigned to a parent reference; if necessary we can even type-cast it.

    When we try to access a shadowed member in the child through a parent reference, the program doesn't consider shadowing any more. It concentrates only on parent members and thus the result would be "10."

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


       · Hello guys,Not every traditional OOP developers know about "Shadows" in Visual...
     

    VISUAL BASIC.NET ARTICLES

    - User-defined Functions using Visual Basic Ap...
    - Understanding Object Binding in VBA
    - Mastering the Message Box
    - Testing a Windows Forms Application
    - Using Visual Basic.NET Features to Code a Wi...
    - Correcting Code in a Windows Forms Applicati...
    - Write Readable Code and Comments for Windows...
    - How to Code and Test a Windows Forms Applica...
    - Adding Features to a Windows Forms Applicati...
    - How to Design a Windows Forms Application
    - LINQ to XML Programming Using Visual Basic.N...
    - Understanding Delegates using Visual Basic.N...
    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek