Abstract Class with simple example in C# and VB.Net

 
An abstract class contains abstract members which define what a subclass should contain. These abstract members only declare that a member of a particular type is required; it does not implement the member. Implementation of abstract members takes place within the derived class.

In Vb.net we use MustInherit in place of abstract in C#.

Example

[Vb.Net ]

Public MustInherit Class AbstractClass
  Sub New()
 
  End Sub
  Public MustOverride Sub Hello()
  Public MustOverride Function GetDouble(ByVal number As Integer) As Long
  Public MustOverride Function getHalf(ByVal number As Integer) As Long
End Class
 
Public Class drivedClass
   Inherits AbstractClass
   Public Overrides Sub Hello()
     ' Hello Message
       MessageBox.Show("Hello")
   End Sub
   Public Overrides Function GetDouble(ByVal number As Integer) As Long
      ' Get Double of any Number
       GetDouble = 2 * number
   End Function
   Public Overrides Function getHalf(ByVal number As Integer) As Long
      ' Get Half of any number
       getHalf = number / 2
   End Function
End Class

[C#]

public abstract class AbstractClass
{
   public AbstractClass()
   {
   }
   public abstract void Hello();
   public abstract long GetDouble(int number);
   public abstract long getHalf(int number);
}
 
public class drivedClass : AbstractClass
{
    public override void Hello()
      {
          // Hello Message
          MessageBox.Show("Hello");
       }
 
   public override long GetDouble(int number)
       {
           // Get Double of any Number
            return 2 * number;
        }
    public override long getHalf(int number)
        {
            // Get Half of any number
            return number / 2;
         }
}