Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 6 - 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 / 46
    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 with parameters during inheritance


    (Page 6 of 6 )

    The previous section already introduced you to constructors in inheritance.  Now, I shall extend the discussion to constructors with parameters. 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(ByVal a As Integer, ByVal b As Integer)
            m_x = a
            m_y = b
        End Sub

    ...
    End Class

    Public Class Second
        Inherits First

        Private m_z As Integer

        Public Sub New(ByVal a As Integer, ByVal b As Integer, ByVal c As Integer)
            MyBase.New(a, b)
            m_z = c
        End Sub

    ...
    End Class

    Public Class Third
        Inherits Second

        Public Sub New()
            MyBase.New(0, 0, 0)
        End Sub

        Public Sub New(ByVal a As Integer, ByVal b As Integer, ByVal c As Integer)
            MyBase.New(10, 20, 30)
        End Sub

    ...

    End Class

    Once you modify 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(10, 20, 30)
            With obj
                Me.Label1.Text = "Sum = " & .getSum & ", Product = " & .getProduct
            End With
        End Sub

    You can observe that I am using a new keyword, "MyBase." It is mainly used to access any of the super class members. In this case, I am executing the constructor of the super class by using "MyBase."

    In this article, I simply wanted to explain the topics of inheritance in OOPS. The sample codes given in this article are neither the best in performance nor the best in programming methodologies.

    Any feedback, suggestions, bugs, errors, improvements etc., are highly appreciated at jag_chat@yahoo.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.

       · 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

    - 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
    Stay green...Green IT