ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

VB.Net program to demonstrate the private methods inside the class

Here, we are going to demonstrate the private methods inside the class in VB.Net.
Submitted by Nidhi, on December 23, 2020

Here, we will create a Student class that contains some private methods inside the class; the private methods will be called inside the public method.

Program/Source Code:

The source code to demonstrate the private methods inside the class is given below. The given program is compiled and executed successfully.

'VB.Net program to demonstrate the private methods inside the class.

Class Student
    Private roll_no As Integer
    Private name As String
    Private fees As Integer
    Private address As String

    Private Sub ReadStart()
        Console.WriteLine("Start reading from user")
    End Sub

    Private Sub ReadStop()
        Console.WriteLine("Stop reading")
    End Sub

    Sub ReadInfo()
        ReadStart()
        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()
        ReadStop()
    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)
    End Sub
End Class

Module Module1
    Sub Main()
        Dim S As New Student

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

Output:

Start reading from user
Enter roll number: 101
Enter student name: Alex carry
Enter student fees: 23457
Enter student address: USA
Stop reading
Student Information
        Roll Number: 101
        Roll Name  : Alex carry
        Fees       : 23457
        address    : USA
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1 that contains the Main() function. Here, we created a Student class that contains 4 data members roll_no, name, fees, address. In the Student class we created two private method ReadStart() and ReadStop() and two public methods ReadInfo() and PrintInfo().

The private methods will be called inside the public methods because we cannot call private members outside the class.

The ReadInfo() method is used to read the student information from the user. The PrintInfo() method is used to print the student detail on the console screen.

The Main() method is the entry point for the program, here we created the object of Student class then called ReadInfo() and PrintInfo() using object to read and print student information.

VB.Net Basic Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.