How to implements Interface in Vb.Net
Public Interface imath
Function add(ByVal a As Integer, ByVal b As Integer) As Integer
Function subst(ByVal a As Integer, ByVal b As Integer) As Integer
End Interface
Public Class math
Implements imath
Public Function add(ByVal a As Integer, ByVal b As Integer) As Integer Implements imath.add
Return a + b
End Function
Public Function subst(ByVal a As Integer, ByVal b As Integer) As Integer Implements imath.subst
Return a - b
End Function
End Class
save page as math.vb
code for interface
Module Module1
Sub Main()
Dim s As New math
Dim d, w As Integer
''Dim obj As New math
Console.WriteLine("enter the value of d & w")
d = Console.ReadLine()
w = Console.ReadLine()
'Console.WriteLine(obj.add(a, b))
'Console.WriteLine(obj.subst(a, b))
'Console.ReadLine()
Console.WriteLine(s.add(d, w))
Console.WriteLine(s.subst(d, w))
Console.ReadLine()
End Sub
End Module
Save as Module1.vb
Public Interface imath
Function add(ByVal a As Integer, ByVal b As Integer) As Integer
Function subst(ByVal a As Integer, ByVal b As Integer) As Integer
End Interface
Public Class math
Implements imath
Public Function add(ByVal a As Integer, ByVal b As Integer) As Integer Implements imath.add
Return a + b
End Function
Public Function subst(ByVal a As Integer, ByVal b As Integer) As Integer Implements imath.subst
Return a - b
End Function
End Class
save page as math.vb
code for interface
Module Module1
Sub Main()
Dim s As New math
Dim d, w As Integer
''Dim obj As New math
Console.WriteLine("enter the value of d & w")
d = Console.ReadLine()
w = Console.ReadLine()
'Console.WriteLine(obj.add(a, b))
'Console.WriteLine(obj.subst(a, b))
'Console.ReadLine()
Console.WriteLine(s.add(d, w))
Console.WriteLine(s.subst(d, w))
Console.ReadLine()
End Sub
End Module
Save as Module1.vb
0 comments: