Here, we will build a student class that includes within the class certain private methods; within the public method, the private methods will be called.
Below is the source code to show the private methods within the class. The program given is compiled and successfully executed.
'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
We created a Module1 module in the program above that includes the Main() function. Here, we have built a student class that includes four roll-no data members, name, fees, address. We built two private ReadStart() and ReadStop() methods and two public ReadInfo() and PrintInfo() methods throughout the student class ().
Within the public methods, the private methods would be named so we do not call outside the class private members.
To read the student information from the user, the ReadInfo() method is used. The PrintInfo() method is used on the console screen to print student details.
The Main() method is the entry point for the program, where we created the Student class object then called ReadInfo() and PrintInfo() using the student knowledge object to read and print.