Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 2 - Inheritance with VB.NET 2005
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 
Actuate Whitepapers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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

Inheritance with VB.NET 2005
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 36
    2006-07-18

    Table of Contents:
  • Inheritance with VB.NET 2005
  • Basic inheritance
  • Adding your own members to the sub class during inheritance
  • Multi-level inheritance in Visual Basic 2005
  • Dealing with constructors during inheritance
  • Dealing with constructors with parameters during inheritance

  • 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

    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!

    Inheritance with VB.NET 2005 - Basic inheritance


    (Page 2 of 6 )

    In the previous section, I simply added a class ("first") with four members.  Now, add one more class named "Second" as follows:

    Public Class Second
        Inherits First

    End Class

    At this moment, visually there exist no members in the class "Second." Now, modify your "Button1_Click" as follows:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim obj As New Second
            With obj
                .X = 10
                .Y = 20
                Me.Label1.Text = .X + .Y
            End With
        End Sub

    Once you execute the above, you will not find any difference in output. Even though the members do not exist physically (or visually), they are available "virtually," as the class is "inherited" from its parent class "first." Let me discuss this point in more detail.

    If a class is defined with the word "inherits," it automatically contains each and every member of its parent/super/base class "virtually." In this case, the class "First" is considered to be the parent/super/base class, whereas the class "Second" is considered to be the child/sub/derived class. All the members existing in the class "First" (m_x, m_y, X, Y) are virtually present in the class "Second," even though you don't define them.

    From now on, I shall use the term "super" class for the "parent" class and "sub" class for the "child" class, so as not to confuse you. 

    A sub class can also have its own members, apart from the members which are automatically available from its super class. This can be achieved by defining your own members within the sub class.  The next section will illustrate this point.

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


       · Hello guys. You can have a first look at inheritance in VB.NET 2005 with this...
       · Thanx SirI was completely fresher in programming and was trying to understand OOPS...
       · Pls provide provisiom for running the code
     

    VISUAL BASIC.NET ARTICLES

    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...
    - Creating and Drawing a Game Map in VB.NET
    - Working with Classes and Properties for Game...
    - Working with Loops, Arrays, and Collections ...
    - Learning Loops in VB.NET for Game Development
    - Learning VB.NET: Working with Variables, Con...
    - The Basics of VB.NET Through Text Game Devel...
    - Learning VB.NET Through Text Game Development
    - 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...





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