ARTICLE

Inheritance in VB.NET

Posted by Munesh Sharma Articles | VB.NET Articles March 14, 2011
In this article we discuss about Inheritance.
 
Reader Level:

Inheritance is a fundamental Object Oriented concept

A class can be defined as a "subclass" of another class.

  • The subclass inherits all data attributes of its superclass
  • The subclass inherits all methods of its superclass
  • The subclass inherits all associations of its superclass
The subclass can:
  • Add new functionality
  • Use inherited functionality
  • Override inherited functionality
Functionality of Inheritance:

fi.gif


Code of above Inheritance Diagram:

Public Module Student
   
Public collegename As [String] = "MCN"
   
Public rollno As Integer
   
Public name As [String]
    Public Sub insert()
       
Console.WriteLine("plz fill student information") 
       
Console.WriteLine("student roll no")
       
rollno = Integer.Parse(Console.ReadLine())|
       
Console.WriteLine("student name")
       
name = Console.ReadLine()

   
End Sub
    Public Sub show()

       
Console.Write("*******************************************")
 
      Console.WriteLine("studen rollno" & "student name" & "student college")
       
Console.WriteLine(rollno & name & collegename)

   
End Sub

End
Module
public Module Students Inherits Student
    Public totalmarks As Integer = 200

    Private getmarks As Integer
   
Public Sub [get]()
       
getmarks = 120
       
Console.WriteLine("max marks")
       
Console.WriteLine(totalmarks)
       
Console.WriteLine("get marks")
       
Console.Write("********************************************************")
        Console.WriteLine(getmarks)

   
End Sub

End
Module

Module
output
   
Sub Main()

       
Dim s1 As New Students()
       
s1.insert()
       
s1.show()
       
s1.[get]()
    End Sub

End Module

Output:

gh.gif

Inheritance Hierarchy

class-tree.gif

  • Each class has one (and only one) super class.
  • Inheritance creates a class hierarchy
  • Classes higher in the hierarchy are more general and more abstract
  • There is no limit to the depth of the class tree

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Nevron Diagram
Become a Sponsor