.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Abstract class and Interface in vb.net

Posted By:satyapriyanayak       Posted Date: March 11, 2013    Points: 40    Category: Visual Studio    URL: http://www.dotnetspark.com  

Abstract class and Interface in vb.net
 

Abstract class: - It is an incomplete class whose object cannot be created. It contains the skeleton of the method, which is implemented by derived class. The abstract class is prefixed by the keyword MustInherit. The methods with in the class are prefixed by MustOverride keyword. The derived class procedure, which implements the abstract class, is prefixed by Overrides keyword.

 

 

Program

 

Public Class Form1

 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim a As New raj1

        a.ravi("Rahul")

    End Sub

 

    Public MustInherit Class raj

        Public MustOverride Sub ravi(ByVal s As String)

    End Class

 

    Public Class raj1

        Inherits raj

        Public Overrides Sub ravi(ByVal s As String)

            MsgBox("Hello:" & s)

        End Sub

    End Class

 

End Class

 

 

Interface: - It is a specification of class members not the implementation of members.

It is the substitute of multiple inheritance, more than one interface can be implemented by a single class. The members with in the interface are not defined. It is public by default. Variables cannot be declared within the interface. Both sub procedure and function procedure can be stored in the interface.

 

Program

 

Public Class Form2

 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim a As New raj1

        a.sagar(25)

        a.amit("Abhijeet")

        MsgBox(a.rahul(10, 20))

 

    End Sub

    Public Interface raj

 

        Sub sagar(ByVal x As Integer)

        Sub amit(ByVal s As String)

        Function rahul(ByVal x As Integer, ByVal y As Integer)

 

    End Interface

 

    Public Class raj1

        Implements raj

 

        Public Sub amit(ByVal s As String) Implements raj.amit

 

            MsgBox("Hello:" & s)

 

        End Sub

 

        Public Function rahul(ByVal x As Integer, ByVal y As Integer) As Object Implements raj.rahul

 

            Dim z As Integer

            z = x + y

            Return z

 

        End Function

 

        Public Sub sagar(ByVal x As Integer) Implements raj.sagar

 

            MsgBox(x)

 

        End Sub

 

    End Class

 

End Class



     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend