Home »
VB.Net »
VB.Net Programs
VB.Net program to demonstrate the 'Friend' keyword
By Nidhi Last Updated : November 11, 2024
'Friend' keyword in VB.Net
Here, we will create a subroutine or procedure with the Friend keyword. The Friend keyword is used to limit the scope a method, Friend method or subroutine cannot be accessed outside the same assembly.
Program/Source Code:
The source code to demonstrate the Friend keyword is given below. The given program is compiled and executed successfully.
VB.Net code to demonstrate the example of 'Friend' keyword
'VB.net program to demonstrate the "Friend" keyword.
Class Sample
' The Fun() is public if we are in the same assembly.
Friend Sub Fun()
Console.WriteLine("Friend function Fun() called")
End Sub
End Class
Module Module1
Sub Main()
Dim obj As New Sample()
obj.Fun()
End Sub
End Module
Output:
Friend function Fun() called
Press any key to continue . . .
Explanation:
In the above program, we created a class Sample that contains a Friend method, which can only be accessed within the same assembly.
After that, we created a module Module1 that contains the Main() method, the Main() method is the entry point for the program. And, we created the object of the Sample class and then called the Fun() method, which will print the appropriate message on the console screen.
VB.Net Basic Programs »