Skip to main content

Inheritance and Property Procedure in VB.NET

Write a program to create class Person. Make at least five properties and one method “show detail” of this class. Now inherit class Student and Faculty from class Person and override method “show detail”. Create objects of Student and Faculty class and call show detail function for both objects to show details in appropriate text boxes.  
Person.vb
Public Class Person
    Dim fname, lname, address As String
    Dim id, age As Integer
    Public Overloads Sub showdetails()
        MsgBox("Faculty Name :" & fname & " " & lname & vbNewLine & "ID :" & id & vbNewLine & "Age :" & age & vbNewLine & "Address" & address)
    End Sub
    Public Overloads Sub showdetails(ByVal s As String)
        MsgBox(s & " Name :" & fname & " " & lname & vbNewLine & "ID :" & id & vbNewLine & "Age :" & age & vbNewLine & "Address" & address)
    End Sub
    Public Property FN As String
        Set(ByVal value As String)
            fname = value
        End Set
        Get
            Return fname
        End Get
    End Property
    Public Property LN As String
        Set(ByVal value As String)
            lname = value
        End Set
        Get
            Return lname
        End Get
    End Property
    Public Property ADD As String
        Set(ByVal value As String)
            address = value
        End Set
        Get
            Return address
        End Get
    End Property
    Public Property IDN As Integer
        Set(ByVal value As Integer)
            id = value
        End Set
        Get
            Return ID
        End Get
    End Property
    Public Property AG As Integer
        Set(ByVal value As Integer)
            age = value
        End Set
        Get
            Return age
        End Get
    End Property
End Class
Student.vb
Public Class Student
    Inherits Person
End Class
Faculty.vb
Public Class faculty : Inherits Person
    'also use Inherits Person
End Class

Form1.vb
Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim s1 As New Student
        s1.FN = TextBox1.Text
        s1.LN = TextBox2.Text
        s1.IDN = Val(TextBox3.Text)
        s1.AG = Val(TextBox4.Text)
        s1.ADD = TextBox5.Text
        s1.showdetails("Student")
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim f1 As New faculty
        f1.FN = TextBox1.Text
        f1.LN = TextBox2.Text
        f1.IDN = Val(TextBox3.Text)
        f1.AG = Val(TextBox4.Text)
        f1.ADD = TextBox5.Text
        f1.showdetails()
    End Sub
End Class
DESIGNING

  

Comments