Home >>VB.Net Built-in Functions >VB.Net program of simple inheritance with student information

VB.Net program of simple inheritance with student information

Write a VB.Net program of simple inheritance with student information

Here, by building PersonalInfo and StudentResultInfo classes, we will show the simple inheritance of student information.

Program :

The source code to display the basic inheritance of student information is given below. The program given is compiled and successfully executed.

'VB.net program to demonstrate the simple inheritance

'with student information.

Module Module1
    Class PersonalInfo
        Dim id As Integer
        Dim name As String
        Public Sub SetPersonalInfo(ByVal i As Integer, ByVal n As String)
            id = i
            name = n
        End Sub
        Public Sub PrintPersonalInfo()
            Console.WriteLine("Id      : {0}", id)
            Console.WriteLine("Name    : {0}", name)
        End Sub
    End Class
    Class StudentResultInfo
        Inherits PersonalInfo
        Dim marks As Integer
        Dim per As Double
        Dim grade As String
        Public Sub SetInfo(ByVal i As Integer, ByVal n As String, ByVal m As Integer, ByVal p As Double, ByVal g As String)
            SetPersonalInfo(i, n)
            marks = m
            per = p
            grade = g
        End Sub
        Public Sub PrintInfo()
            Console.WriteLine("Marks   : {0}", marks)
            Console.WriteLine("Per     : {0}", per)
            Console.WriteLine("Grade   : {0}", grade)
        End Sub
    End Class
    Sub Main()
        Dim S As New StudentResultInfo()

        S.SetInfo(10, "shetty", 300, 12.6, "C")
    End Sub
End Module
Id : 10
Name : shetty
Marks : 300
Per : 12.6
Grade : C

We created a Module1 module in the program above. Here, to apply easy inheritance, we created two PersonalInfo and StudentResultInfo classes.

PersonalInfo includes two SetPersonalInfo() and PrintPersonalInfo() methods for configuring and printing a student's personal information. StudentResultInfo also provides two SetInfo() and PrintInfo() methods for setting up and printing a student's academic information.

Finally, we created the Main() function, which is the program entry point, where we created the StudentResultInfo class object and set and print student information on the console screen.

No Sidebar ads