VB.Net Program to Create an Object of Class Inside Another Class

You are currently viewing VB.Net Program to Create an Object of Class Inside Another Class

VB.Net program to create an object of class inside another class

'VB.Net program to create an object of class inside another class.

Class Marks
    Private marks As Integer

    Sub SetMarks(ByVal m As Integer)
        marks = m
    End Sub

    Sub PrintMarks()
        Console.WriteLine(vbTab & "marks    : " & marks)
    End Sub
End Class

Class Student
    Private roll_no As Integer
    Private name As String
    Private fees As Integer
    Private address As String
    Public mark As New Marks
    Sub ReadInfo()
        Console.Write("Enter roll number: ")
        roll_no = Integer.Parse(Console.ReadLine())

        Console.Write("Enter student name: ")
        name = Console.ReadLine()

        Console.Write("Enter student fees: ")
        fees = Integer.Parse(Console.ReadLine())

        Console.Write("Enter student address: ")
        address = Console.ReadLine()

        Console.Write("Enter student marks: ")
        mark.SetMarks(Integer.Parse(Console.ReadLine()))
    End Sub

    Sub PrintInfo()
        Console.WriteLine("Student Information")
        Console.WriteLine(vbTab & "Roll Number: " & roll_no)
        Console.WriteLine(vbTab & "Roll Name  : " & name)
        Console.WriteLine(vbTab & "Fees       : " & fees)
        Console.WriteLine(vbTab & "address    : " & address)
        mark.PrintMarks()
    End Sub
End Class

Module Module1
    Sub Main()
        Dim S As New Student

        S.ReadInfo()
        S.PrintInfo()
    End Sub
End Module

Output

Enter roll number: 101
Enter student name: Amit Gupta
Enter student fees: 12456
Enter student address: Katni
Enter student marks: 455
Student Information
        Roll Number: 101
        Roll Name  : Amit Gupta
        Fees       : 12456
        address    : Katni
        marks    : 455
Press any key to continue . . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply