Interfaces,like classes, define a set of properties,methods,and events. But unlike classes,interfaces do not provide

implementation. They are implemented by classes,and defined as seprate entoties from classes.


An interface represents a contract, in that a class that implements an interface must implement every aspect of that

interface exactly as it is defined.


With interfaces,you can define features as small groups of closely related members. You can devlop enhanced

implementations for your interfaceswithout jeopardizing existing code,thus minimizing compatibility problems.

You can also add new features at any time by developing additional interfaces and implementations.


Interface members must be methods,properties,events,or type definations.


There are several other reasons why you might want to use interfaces instead of class inheritance:

  • Interfaces are better suited to situations in which your applications require many possibly unrelated object types

to provide certain functionality.

  • Interfaces are more flexible than base classes because you can define a single implementation that can 

implement multiple interfaces.

  • Interfaces are better in situations in which you do not need to inherit implementation from a base class.


  • Interfaces are useful in cases where you cannot use class inheritance.

For example, structures cannot inherit from classes,but they can implement interfaces.


Interface Iface1

            Function getNetSal() as Integer

            Property Basic() as Integer

            ReadOnly Property DA() as Integer

            ReadOnly Property HRA() as Integer

            ReadOnly Property PF() as Integer

            ReadOnly Property net() as Integer

End Interface


Public class Salary

            Implements Iface1

            Public netsal as Integer

            Private netSal as Integer

            Public Function getNetSal() as Integer Implements Iface1.getNetSal

netSal=Basic+((Basic*DA)/100) +((Basic*HRA)/100) –


                        return netsal

            End Function

            Property Basic() as Integer Implements Iface1.Basic


                                    Return basicsal

                        End Get

                        Set(ByVal Value as Integer)


                        End Set

            End Property

            Private ReadOnly Property HRA() as Integer Implements Iface1.HRA


                                    Return 10

                        End Get

            End Property

            Private ReadOnly Property PF() as Integer Implements Iface1.PF


                                    Return 20

                        End Get

            End Property

            Private ReadOnly Property DA() as Integer Implements Iface1.DA


                                    Return 30

                        End Get

            End Property

            Private ReadOnly Property NET() as Integer Implements Iface1.NET


                                    Return NETSAL

                        End Get

            End Property

End class

Module moduleInterface

            Sub Main()

                        Dim obj as New Salary




Dim a as Iface1

a=New Salary




            End Sub

End Module




Average Rating (0)
by Anjali   vaghela  in VB.Net  on 3/24/2015 10:31:00 PM  

Post Your Comment