ARTICLE

Abstract classes in VB.NET

Posted by Munesh Sharma Articles | VB.NET Articles March 22, 2011
In this article we will describe the functionality of abstract classes,
Download Files:
 
Reader Level:

We know that all the classes can be separated in to two categories, concrete classes and abstract classes  

Concrete classes:-"Classes are concrete classes if they support object instantiations using the new operator."

Abstract classes:-"Classes are abstract classes  if they do not support object instantiations." 

Now we will discuss about the Abstract classes in VB.NET, explaining why we use the abstract classes in programming.because an abstract base class enable you to define a programming contract with the partially completed implementation and other functionality that are given bellow 

  • Defining a class as an abstract class enables you to document your intention to use the class exclusively as base class.
  • An abstract base class is like  a concrete base class in that it may contain both override and non override methods.
  • Abstract base classes are more flexible than concrete base classes because they can also contain abstract members.   
                                              Abstract-classes.gif

Syntax of abstract classes in VB.NET:- When you create the definition for the base class, you must add the MustInherit keyword to make it abstract

Public MustInherit Class className
    Public Overridable Function functionName() As String
        Return " That are vehicle"
    End Function
    'othere class member function omity for clarity

End
Class

Note:-A class defined with the MustInherit keyword is abstract and , therefore ,can not be directly used to create an object.

coding for abstract classes in VB.NET:
 
 
Module Module1 
     Public MustInherit Class AbstractClass
         'declaring an abstract class with MustInherit keyword
 
        Public MustOverride Function Add() As Integer
 
        Public MustOverride Function Subs() As Integer
 
        'declaring two abstract members with MustOverride keyword
 
    End Class
 
     Public Class AbstractOne
         : Inherits AbstractClass
         'implementing the abstract class by inheriting
 
        Dim i As Integer = 50
         Dim j As Integer = 30
         'declaring two integers
 
         Public Overrides Function Add() As Integer
 
            Return i + j
         End Function
 
        'implementing the add method
 
         Public Overrides Function Subs() As Integer
 
            Return i - j
         End Function
 
        'implementing the subs method
 
     End Class
 
    Public Class Abstracttwo : Inherits AbstractClass
         Dim X As Integer = 34
         Dim y As Integer = 30
         Public Overrides Function Add() As Integer
 
            Return X + y 
         End Function
 
         Public Overrides Function Subs() As Integer
 
            Return X - y 
         End Function
 
    End Class
 
    Sub Main()
         Dim abs As New AbstractOne()
         'creating an instance of AbstractOne
 
        Console.WriteLine("first class Sum is" & " " & abs.Add())
         Console.WriteLine("first Substraction is " & " " & abs.Subs())
         Dim abt As New Abstracttwo()
         'creating an instance of AbstractOne
 
        Console.WriteLine("second class Sum is" & " " & abt.Add())
         Console.WriteLine("second class Substraction is " & " " & abt.Subs())
         'displaying output
 
    End Sub

 End
Module

Output:

                Abstractclass-output.gif


Login to add your contents and source code to this article
share this article :
post comment
 

Escribir en vb.net este fragmento de código using System; public abstract class BaseMasterPage : System.Web.UI.MasterPage { public event EventHandler PricesDoubled; protected virtual void OnPricesDoubled(EventArgs e) { if (PricesDoubled != null) PricesDoubled(this, e); } public abstract void RefreshRecentProductsGrid(); public abstract string GridMessageText { get; set; } } que se encuentra en link: http://translate.google.com.co/translate?hl=es&sl=en&tl=es&u=http%3A%2F%2Fwww.asp.net%2Fmaster-pages%2Ftutorials%2Fnested-master-pages-cs

Posted by Jose Dur Aug 13, 2011
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • 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.
    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.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor