Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 5 - 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  
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

Inheritance with VB.NET 2005
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 44
    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


    Inheritance with VB.NET 2005 - Dealing with constructors during inheritance


    (Page 5 of 6 )

    I already introduced constructors in my previous series of articles covering OOPS using Visual Basic 2005. If you are very new to constructors, I strongly suggest you go through my previous series before continuing this section.

    During inheritance, the constructors are executed starting from the highest super class through the lowest sub class in the form of a hierarchy.  Now, let us modify our hierarchy of classes as follows:

    Public Class First

        Private m_x As Integer
        Private m_y As Integer

        Public Sub New()
            m_x = 10
            m_y = 10
        End Sub

    ...

    End Class

    Public Class Second
        Inherits First

        Private m_z As Integer

        Public Sub New()
            m_z = 20
        End Sub

    ...

    End
    Class

    Public Class Third
        Inherits Second

        Public Function getProduct() As Integer
            Dim s As Integer
            s = Me.X * Me.Y * Me.Z
            Return s
        End Function
    ...

    End Class

    Now that you have modified the hierarchy as above, let us try to modify the testing code as well:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim obj As New Third
            With obj
                Me.Label1.Text = "Sum = " & .getSum & ", Product = " & .getProduct
            End With
        End Sub

    Now, you can observe from the above code that I didn't assign any values to the properties during testing.  I just created the object and all the values, which are default values, have been assigned during the execution of constructors at various levels.

    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
       · The final example with of the constructor inheritance should be MyBase.New(a,b,c) It...
       · I agree that it would be best to pass the parameters in but overall it was a good...
     

    VISUAL BASIC.NET ARTICLES

    - 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...
    - Creating and Drawing a Game Map in VB.NET (F...
    - 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...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT