39 Inheritance in VB.NET

Code:

Module Module1

    Class Faculty
        Public name As String
        Public age As Integer

        Sub accept()
            Console.WriteLine()
            Console.WriteLine("Enter name and age of Faculty: ")
            name = Console.ReadLine()
            age = Console.ReadLine()
        End Sub

        Sub display()
            Console.WriteLine("Name: " & name)
            Console.WriteLine("Age: " & age)
        End Sub

    End Class

    Class Student
        Inherits Faculty
        Public roll As Integer
        Public name As String
        Public per As Double

        Sub getdata()
            Console.WriteLine()
            Console.WriteLine("Enter rollno , name and percentage of Student: ")
            roll = Console.ReadLine()
            name = Console.ReadLine()
            per = Console.ReadLine()
        End Sub

        Sub print()
            Console.WriteLine("Name: " & name)
            Console.WriteLine("Roll: " & roll)
            Console.WriteLine("Percentage: " & per)
        End Sub

    End Class

    Sub Main()
        Dim s1 As Student = New Student()

        s1.accept()
        s1.display()
        s1.getdata()
        s1.print()

        Console.ReadKey()
    End Sub

End Module





Ouput:

Inheritance in VB.NET

Previous
Next Post »