| Public Class One --- --- End Class Public Class Two Inherits One --- --- End Class |
Using Inheritance we can use the variables, methods, properties, etc, from the base class and add more functionality to it in the derived class. The following code demonstrates the process of Inheritance in Visual Basic.
| Imports System.Console Module Module1 Sub Main() Dim ss As New Two() WriteLine(ss.sum()) Read() End Sub End Module Public Class One 'base class Public i As Integer = 10 Public j As Integer = 20 Public Function add() As Integer Return i + j End Function End Class Public Class Two Inherits One 'derived class. class two inherited from class one Public k As Integer = 100 Public Function sum() As Integer 'using the variables, function from base class and adding more functionality Return i + j + k End Function End Class |
Output of above code is sum of i, j, k as shown in the image below.
No comments:
Post a Comment