What is abstract class with example program in a c# code
What is abstract class with example program in a c# code
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Jul 7, 2012, 6:57 AM
Notice that abstract methods are virtual and therefore exhibit polymorphic behaviour. However, unlike a normal 'virtual' method, an abstract method cannot have a body.
Satyapriya NayakPosted Jul 7, 2012, 6:22 AM
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 Form1Private 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 Form2Private 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
For Csharp code Please refer the below links
http://www.codeproject.com/Articles/6118/All-about-abstract-classes
http://www.c-sharpcorner.com/uploadfile/annathurai/abstract-class-in-C-Sharp/
Thanks