Difference Between Interface And Abstract Class in VB.NET
In this article we will learn What is the difference between interface and abstract class in VB.NET
In this article we will learn What is the difference between interface and abstract class in VB.NET.
A user defined data type similar to class but contains all abstract methods.
All methods are abstract and public by default.
All such methods are overridden in child class.
Allows to implement the multiple inheritance.
A class can inherit only one other class but any number of interfaces.
All interfaces in .NET starts with I.
implements keyword to implement the interface.
use the Interface keyword to create an interface.
The following code demonstrates the use of interface.
Public Sub ShowSalary() Implements IHr.ShowSalary
System.Console.WriteLine("Salary will be on 10th")
Public Sub Budget() Implements IFinance.Budget
System.Console.WriteLine("Budget is 10 L")
Public Sub Leaves() Implements Common.Leaves
System.Console.WriteLine("Leaves are 10 Cs, 20 EL")
Public Shared Sub Main()
Dim h As IHr = New ERP()
The mustinherit keyword is used to create abstract classes in VB.NET.
An abstract class is a special kind of class that cannot be instantiated. So the question is why we need a class that cannot be instantiated? An abstract class is only to be sub-classed (inherited from). In other words, it only allows other classes to inherit from it but cannot be instantiated. The advantage is that it enforces certain hierarchies for all the subclasses. In simple words, it is a kind of contract that forces all the subclasses to carry on the same hierarchies or standards.
Public MustInherit Class AbstractClass
Public MustOverride Function Add() As Integer
Public MustOverride Function Mul() As Integer
Public Class AbstractOne
Dim i As Integer = 20
Dim j As Integer = 30
Public Overrides Function Add() As Integer
Return i + j
Public Overrides Function Mul() As Integer
Return i * j
Dim abs As New AbstractOne()
WriteLine("Sum is" & " " & abs.Add())
WriteLine("Multiplication is" & " " & abs.Mul())
Difference between interface and abstract class in VB.NET.
These are some differences between abstract class and interfaces.
- An abstract class may contain complete or incomplete methods. Interfaces can contain only the signature of a method but no body. Thus an abstract class can implement methods but an interface can not implement methods.
- An abstract class can contain fields,constructors, or destructors and implement properties. An interface can not contain fields, constructors, or destructors and it has only the property's signature but no implementation.
- An abstract class cannot support multiple inheritance, but an interface can support multiple inheritance. Thus a class may inherit several interfaces but only one abstract class.
- A class implementing an interface has to implement all the methods of the interface, but the same is not required in the case of an abstract Class.
- Various access modifiers such as abstract, protected, internal, public, virtual, etc. are useful in abstract Classes but not in interfaces.
- Abstract classes are faster than interfaces.